Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reading a Line into an Array

by scrubber (Sexton)
on May 31, 2001 at 12:22 UTC ( #84494=note: print w/replies, xml ) Need Help??


in reply to Reading a Line into an Array

thanks, this is all very helpful. I would like to point out that I already knew about $array[-1] for the last element, if you check out the middle of the code. But thanks again, I've got lots of stuff to work with!
-scrubber

Replies are listed 'Best First'.
Re: Re: Reading a Line into an Array
by larryk (Friar) on May 31, 2001 at 14:28 UTC
    if you undef $/; then you can say my @array = split /\n+/, <DATA>; and this will ignore all the empty lines.

    Update
    Sorry about the minimalist post - didn't have any time earlier. The reason this works is that $/ (newline by default) is used as the end-of-line character when reading from a filehandle. If you undefine it then no end of line is seen and the whole file is "slurped" in, in one go. "split"ting this on one (or more) newlines does the "chomp"ing for you while also returning a list. hope this makes it a bit clearer.

    "Argument is futile - you will be ignorralated!"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2021-11-27 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?