in reply to How not to remove trailing empty strings from an array

Close, but subtly different (imho), it
is an infinite loop if @msgstr becomes the empty list because then -1 returns undef, which causes length to return undef, which is false and gets negated.
You could fix this by using pop @msgstr while !length($msgstr[-1]//0); instead (perl v5.10 and up)

Replies are listed 'Best First'.
Re^2: How not to remove trailing empty strings from an array
by ambrus (Abbot) on Apr 16, 2013 at 16:51 UTC

    My actual fix was

    pop @msgstr while @msgstr && !length($msgstr[-1]);
Re^2: How not to remove trailing empty strings from an array
by LanX (Saint) on Apr 16, 2013 at 17:21 UTC
    Nope, I suppose ambrus also wants to strip trailing ...
    ... undefs

    Cheers Rolf

    ( addicted to the Perl Programming Language)