Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by GrandFather (Saint)
on May 01, 2014 at 23:32 UTC ( [id://1084704]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!user/bin/perl
    use warnings;
    ...
    my @array = (1, 2, 3, 4, 2, 1, 2, 0, 1, 0, 0);
    my @newArray = grep{!$_} @array;
    push @newArray, grep {$_} @array;
    

Log In?
Username:
Password:

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

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

    No recent polls found