Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by SuicideJunkie (Vicar)
on May 01, 2014 at 22:13 UTC ( [id://1084699]=note: print w/replies, xml ) Need Help??


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

Here's another way to do it if all the false values are just zero:

my $size = @array; @array = grep {$_} @array; unshift @array, (0) x ($size - @array);
  • 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://1084699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2024-04-25 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found