in reply to move all 0s in an array to the beginning keeping other elements order same
How about:
my @new_array=(); for my $i (@array) { if ($i) { push @new_array, $i; } else { unshift @new_array, $i; } }
or, perhaps:
my @new_array = ( grep( { ! $_ } @array), grep( { $_ } @array) );
Note: Untested....
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|