LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2008, 12:35 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Perl Newbie Questions


I have this section of my Perl script. The script is really long so I truncated most of it, but here is the section that matters:

PHP Code:
# Read the seed files
#Globals
my @am_dirs = ('am1''am2''am3''am-cam');
my @seed_files = ( 'Example.seed''Example2.seed''Example3.seed',
                 
'Example4.seed''Example5.seed''Example6.seed' );


foreach 
my $am ( @am_dirs ) {

    
my $path $seedfile_path $am;

    foreach 
my $seed ( @seed_files ) {

    
my  $file $path '/' $seed;

        
my @tmparray split /\./, $seed;
        
my $sysContact = @tmparray[0];

        
# test for file
        
if ( -e $file && -f $file ) {

            
#print "File: $file\n";

            # open file and read contents
            
foreach my $device ( <$file> ) {

                
# remove white space

                # push names into %devices
                
$devices{$device} = $sysContact;
            }
        }
    }


when I run the script I get this output because it cant read the files. In my array, the files are there and the path is correct but I can clearly see that the script cannot read any of the files because there isnt a "OPEN" statement anywhere.

PHP Code:
./npt_devices.pl
File
: /home/staging/trunk/seed/am1/SNIFFER.seed
File
: /home/staging/trunk/seed/am2/SNIFFER.seed
File
: /home/staging/trunk/seed/am2/NAM.seed
File
: /home/staging/trunk/seed/am3/SNIFFER.seed
File
: /home/staging/trunk/seed/am-cam/NGENIUS.seed
File
: /home/staging/trunk/seed/am-cam/NETQOS.seed
File
: /home/staging/trunk/seed/am-cam/CISCOWORKS.seed
File
: /home/staging/trunk/seed/am-cam/SNIFFER.seed
File
: /home/staging/trunk/seed/am-cam/NAM.seed
File
: /home/staging/trunk/seed/am-cam/NETIQVOIP.seed 
How can I get this section to read data from my seed files? I need to have the data's output sent to a hash.

Last edited by metallica1973; 03-11-2008 at 01:36 PM.
 
Old 03-11-2008, 01:32 PM   #2
exscape
Member
 
Registered: Aug 2007
Location: Sweden
Distribution: OS X, Gentoo, FreeBSD
Posts: 82

Rep: Reputation: 15
What does the file contents look like?
Also, how "newbie" are you? Unless you're reaally new this is probably out of my league.

PHP Code:
 if ( -e $file && -f $file ) {

            
#print "File: $file\n";
            
open F"<"$file or die "Unable to open file $file: $!\n";
            
# open file and read contents
            
foreach my $device ( <F> ) {
               
# ... split and save data here
            
}
            
close F;
        } 
Perhaps?

I suppose more info is needed, though
 
Old 03-11-2008, 01:51 PM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Better said, how can I read multiple files from an array like in my script?

PHP Code:
my @seed_files = ( 'Example.seed''Example2.seed''Example3.seed',
                 
'Example4.seed''Example5.seed''Example6.seed' ); 
something like this:

PHP Code:
open (@seed_files
or

PHP Code:
open (<@seed_files>) 
help!

Last edited by metallica1973; 03-11-2008 at 02:36 PM.
 
Old 03-11-2008, 04:43 PM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
the way I cheat is like so:

Code:
@ARGV = <*.seed>;

while (<>) {
        # do stuff here
        print
}
 
Old 03-11-2008, 04:46 PM   #5
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Do you really have big ears thanks
 
Old 03-12-2008, 05:32 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
no, (nose isn't small though)
;-)

bigears
 
Old 03-12-2008, 07:56 AM   #7
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Sorry, one more stupid question:

where would I plug

PHP Code:
@ARGV = <*.seed>;

while (<>) {
        
# do stuff here
        
print

into the equation? I am such a novice at Perl.
 
Old 03-12-2008, 08:36 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
stick it where the foreach is, or
Code:
foreach my $file (<>) {

	print $file;
}
more info would help
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie help with a perl script justinjoseph24 Programming 8 03-12-2008 05:49 PM
perl regex newbie lrt Programming 7 11-15-2007 08:27 PM
good place to ask newbie questions about perl? wijnands Linux - Newbie 2 04-09-2004 03:44 AM
newbie to html/perl/apache needs help doublefailure Linux - Software 5 07-09-2002 08:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration