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

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

by dbuckhal (Friar)
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?
[LanX]: it's considered spamming to advertise threads here
[LanX]: just wait

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-04-24 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?