Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by kennethk (Abbot)
on May 01, 2014 at 21:56 UTC ( [id://1084694]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @array = sort {-($a == 0) || $b == 0} @array;
    
  2. or download this
    @array = sort {($b == 0)-($a == 0)} @array;
    
  3. or download this
    @array = sort {!$b - !$a} @array;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-18 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found