Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by sundialsvc4 (Abbot)
on May 02, 2014 at 12:04 UTC ( [id://1084780]=note: print w/replies, xml ) Need Help??


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

With all due respect to SO, it is definitely the case that PerlMonks is the “go-to site” on the Internet for Perl related questions.   The greatest concentration of [Perl, and other things] expertise that I have ever found is here, and generally quite willing to jump in and help ... with examples ... for even some mighty esoteric questions.

As others have said, I would solve this problem by using grep to curry out all of the elements that are not zero, then if necessary unshift a list containing an appropriate number of zeros onto the front of the result.   This will have the effect of “moving the zeros to the front” without otherwise altering the order of the elements, although it does so in a different (but equivalent) way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found