Russ has asked for the wisdom of the Perl Monks concerning the following question:
This post was moved from Categorized Questions and Answers
Please do not vote for this node. It will affect the wrong user.
Thank you -- Q&AEditors
Please do not vote for this node. It will affect the wrong user.
Thank you -- Q&AEditors
I wish to populate an array from a text file. Each line of text should be a list item.
Here's what I've come up with, but results in "Use of uninitialized value at line 11" error. What am I missing?
1 #!/usr/bin/perl -w 2 use strict; 3 4 $file = "/path/file"; 5 open (<FH>, "< $file") or die "Can't open $file for read: $!"; 6 while (<FH>) { 7 push (@lines, $line); 8 } 9 close FH or die "Cannot close $file: $!"; 10 11 print join(',', @lines); # see if it worked
|
---|
Replies are listed 'Best First'. | |
---|---|
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 | |
Re: How to populate array with lines from text file? (Moved from Q&A)
by repson (Chaplain) on Dec 09, 2000 at 14:39 UTC | |
Re: How to populate array with lines from text file? (Moved from Q&A)
by Fastolfe (Vicar) on Dec 09, 2000 at 15:40 UTC | |
Re: How to populate array with lines from text file? (thanks)
by ybiC (Prior) on Dec 09, 2000 at 18:55 UTC |
Back to
Seekers of Perl Wisdom