Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://745546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found