in reply to Re: Detecting Last line of a file
in thread Detecting Last line of a file

Rather than keeping an extra variable around just test $address:

print ", " if $address; # won't be done the first time

Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^3: Detecting Last line of a file
by davidrw (Prior) on Jun 18, 2005 at 22:51 UTC
    Why wouldn't it be done the first time? That doesn't work unless $content[0] is somehow false .. since we're looping through @content and they're presumably all non-false, then $address is always set. Best way to get rid of the temp var is to just use split, or dpending on context (i.e. if you're reading a file) you could do print "," if $. > 1;.

      Quite right. That's what comes of answering before coffee! I was thinking in terms of concatenating the addresses into a variable which would be undef the first time round.


      Perl is Huffman encoded by design.