Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 studying the Monastery: (6)
As of 2014-12-20 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (99 votes), past polls