Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: move all 0s in an array to the beginning keeping other elements order same

by dbuckhal (Hermit)
on May 02, 2014 at 04:09 UTC ( #1084724=note: print w/replies, xml ) Need Help??


in reply to move all 0s in an array to the beginning keeping other elements order same

Probably a duplicate, but my contribution:
$ perl -le '@x = (1, 2, 3, 4, 2, 1, 2, 0, 1, 0, 0); for ( @x ) { ( $_ ) ? push @y, $_ : unshift @y, $_; } print "@y\n"; ' __output__ 0 0 0 1 2 3 4 2 1 2 1
  • Comment on Re: move all 0s in an array to the beginning keeping other elements order same
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-08-12 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?