Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Split on new line

by gone2015 (Deacon)
on Feb 21, 2009 at 16:24 UTC ( [id://745546] : note . print w/replies, xml ) Need Help??

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:

open FILE, $ARGV[0] or die "Can't open $ARGV[0] for reading: $!\n"; while (<FILE>){ print "Line: $_"; }
...though you may want the whole thing in an array for other reasons.