anilmwr has asked for the wisdom of the Perl Monks concerning the following question:
I want to move all 0s in an array to the beginning keeping other elements order same.
Is there any better way to do this?@array = (1, 2, 3, 4, 2, 1, 2, 0, 1, 0, 0); @array1 = (); @array2 = (); foreach $i (@array) { push($i, @array1) if $i == 0; push($i, @array2) if $i != 0; } @new_array = (@array1, @array2);
Back to
Seekers of Perl Wisdom