Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: TIMTOWTDI Challenge: Zero'ing Out An Array

by hbm (Hermit)
on Sep 27, 2011 at 16:10 UTC ( [id://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}

Replies are listed 'Best First'.
Re^2: TIMTOWTDI Challenge: Zero'ing Out An Array
by Corion (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://928111]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found