in reply to Reading a Line into an Array

There are several ways to go. If you are really only concerned with the last empty line, just remove it with:
pop @array; #pop removes the last item of an array
But maybe you want to remove each newline at the end of the individual items?
chomp foreach( @array ); # the foreach loop 'remembers' the value
Or do you want remove all empty items as well?
chomp foreach( @array ); @array = grep { length } @array; #grep leaves out all items that have +a 'false' length
If you want, take a look at grep, foreach and length.

Hope this helps,

Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: Re: Reading a Line into an Array
by grinder (Bishop) on May 31, 2001 at 11:43 UTC

    Actually, chomp will operate on an array if you ask it nicely:

    chomp(@a);

    Try out this one-liner if you like:

    perl -e '@a=("a","b","c\n");chomp @a;$"="-";print "[@a]\n"'

    --
    g r i n d e r
Re: Re: Reading a Line into an Array
by Chady (Priest) on May 31, 2001 at 11:46 UTC
    chomp foreach( @array );

    Didn't you just mean  chomp (@array); ?


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/