in reply to Split on new line
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.open FILE, $ARGV[0] or die "Can't open $ARGV[0] for reading: $!\n"; while (<FILE>){ print "Line: $_"; }
|
---|