more useful options | |
PerlMonks |
Re: Split on new lineby gone2015 (Deacon) |
on Feb 21, 2009 at 16:24 UTC ( [id://745546]=note: print w/replies, xml ) | Need Help?? |
If you'd used use strict, it might have brought to your attention the fact that you are attempting to split a variable, $file, which you haven't declared. If you'd used use warnings, it would have told you that $file is undefined when you attempt to split it. In any case, @file = <FILE> has already read the file into an array of lines. So no split is required and you can simply: foreach (@file) Note, however that the lines in the array have the newline at the end, so you may want to either chomp the individual lines, or chomp the entire array. Mind you, it's possibly simpler to: ...though you may want the whole thing in an array for other reasons.
In Section
Seekers of Perl Wisdom
|
|