Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: TIMTOWTDI Challenge: Zero'ing Out An Array

by hbm (Hermit)
on Sep 27, 2011 at 16:10 UTC ( #928111=note: print w/ replies, xml ) Need Help??


in reply to TIMTOWTDI Challenge: Zero'ing Out An Array

No map??

map{pop@array}@array

Late addition:

{pop@array&&redo}


Comment on Re: TIMTOWTDI Challenge: Zero'ing Out An Array
Select or Download Code
Re^2: TIMTOWTDI Challenge: Zero'ing Out An Array
by Corion (Pope) on Sep 28, 2011 at 08:19 UTC

    That won't work if the array contains a zero or an empty string:

    > perl -wle "{pop@ARGV && redo}; print for @ARGV" 1 2 0 4 5 1 2

    A fix would be to check @ARGV:

    > perl -wle "{pop@ARGV,@ARGV && redo}; print for @ARGV" 1 2 0 4 5

    ... possibly with aliasing @_ to the array:

    > perl -wle "{local *_=\@ARGV; pop && redo}; print for @ARGV" 1 2 0 4 +5

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-07-30 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls