Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Parsing multiline string line by line

by hbm (Hermit)
on Feb 19, 2009 at 21:36 UTC ( [id://745202]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Parsing multiline string line by line
in thread Parsing multiline string line by line

But that puts the whole file into the first element of the array. (Change your print to print "|$_|\n" for @fin; and you'll see only one element.)

You probably want this:

$/ = undef; open "FIN", "<raja.txt" or die "cant open :$!"; my @fin = split/\n/,<FIN>; close FIN; print "|$_|\n" for @fin;

Or to also get rid of blank lines:

... my @fin = grep {$_} split /\n/, <FIN>;

Update: Square brackets in my original post created a link I didn't intend. I changed them to pipes. And alternatively, you could just print scalar @fin to confirm how many items you slurped.

Replies are listed 'Best First'.
Re^4: Parsing multiline string line by line
by Jayson (Novice) on Feb 20, 2009 at 14:35 UTC
    Thank you for the correction! Odd that there are several examples of the array assignment floating around the web and I filed it away as valid without testing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-26 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found