http://qs321.pair.com?node_id=84494


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!"