in reply to can't remove all zeroes from an array
The problem is that as you remove elements you invalidate the index that you are using. However, Perl has a much better way of doing what you want. Consider:
use strict; use warnings; my @arry = (9,0,0,5,3,0,0,0,2,0,1,0); print "@arry \n"; @arry = grep {$_} @arry; print "@arry \n";
Prints:
9 0 0 5 3 0 0 0 2 0 1 0 9 5 3 2 1
The magic is grep.
|
|---|