Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to populate array with lines from text file? (Moved from Q&A)

by Russ (Deacon)
on Dec 09, 2000 at 10:47 UTC ( #45869=note: print w/ replies, xml ) Need Help??


in reply to How to populate array with lines from text file? (Moved from Q&A)

The main problem was $line. You should use $_ instead.

After a few other clean-ups, this works:

#!/usr/bin/perl -w use strict; my $file = "junk"; open (FH, "< $file") or die "Can't open $file for read: $!"; my @lines; while (<FH>) { push (@lines, $_); } close FH or die "Cannot close $file: $!"; print @lines; # see if it worked

Russ
Brainbench 'Most Valuable Professional' for Perl


Comment on Re: How to populate array with lines from text file? (Moved from Q&A)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-09-18 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls