Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How not to remove trailing empty strings from an array

by Neighbour (Friar)
on Apr 16, 2013 at 14:32 UTC ( [id://1028926]=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found