Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Re: Re: Re: Unix Perl and Html

by meccaxlr (Initiate)
on Aug 27, 2001 at 18:33 UTC ( #108134=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: Unix Perl and Html
in thread Unix Perl and Html

Thanks alot once again! Do you have any advice on setting up an array, I have to take input from 3 different files and put them into a nice array. Any suggestions? Is it difficult .


Comment on Re: Re: Re: Re: Re: Re: Unix Perl and Html
reading multiple files into an array
by thatguy (Parson) on Aug 27, 2001 at 20:09 UTC
    something like this will read in all the files listed in @files. It also cuts down on repetitive code and allows scalability.

    my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open(FILE," $filename") || die "Cannot open $filename: $!\n"; while(<FILE>) { push @allfiles, $_; } close(FILE); }

    -p
      Better would be:
      my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open FILE, $filename || die "Cannot open $filename for reading: $!\n"; push @allfiles, $_ while (<FILE>); close FILE; } # Or (and even more Perlish) ... my @files= qw| /path/to/file1 /path/to/file2 /path/to/file3 |; my @allfiles; for my $filename(@files){ open FILE, $filename || die "Cannot open $filename for reading: $!\n"; push @allfiles, <FILE>; close FILE; }

      ------
      /me wants to be the brightest bulb in the chandelier!

      Vote paco for President!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://108134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-11-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls