Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by kcott (Archbishop)
on May 01, 2014 at 22:16 UTC ( [id://1084700]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/env perl -l
    
    ...
    @array = map { $_ == 0 ? ++$zeros && () : $_ } @array;
    unshift @array, (0) x $zeros;
    print "@array";
    
  2. or download this
    1 2 3 4 2 1 2 0 1 0 0
    0 0 0 1 2 3 4 2 1 2 1
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found