--- Robert Citek <[EMAIL PROTECTED]> wrote:
> At 05:27 PM 9/13/2001 +0200, Jorge Goncalvez wrote:
> >Hi, How in Perl you can store each line of a file in an array?
> 
> From section 4.1 in the Perl Cookbook
> (http://www.oreilly.com/catalog/cookbook/):
> 
> @bigarray = ();
> open(DATA, "< mydatafile")       or die "Couldn't read from datafile: $!\n";
> while (<DATA>) {
>     chomp;
>     push(@bigarray, $_);
> }
> 
> Regards,
> - Robert

A couple of comments.

I would try to avoid using DATA as the filehandle as this may cause confusion with the 
__DATA__
token.  Also, if you're going to read the entire file into an array, this is faster 
and (IMHO)
easier to understand:

    open INDATA, "< $file" or die "Couldn't open $file for reading: $!";
    chomp ( my @bigarray = <INDATA> );

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to