Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
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 avoiding work at the Monastery: (7)
As of 2019-10-14 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?