in reply to can't remove all zeroes from an array
Consider what happens before the splice, when $i is 1:
9,0,0,5,3,0,0,0,2,0,1,0 ^ $i is 1
9,0,5,3,0,0,0,2,0,1,0 ^ $i is 1
$arry[$i] is still 0
You need to keep spliceing while it remains zero, change your if to a while.
Now think about what happens when you've just spliced that last 0. $i points past the end of the array, so you need to add a check for that into the while condition:
while ( $i <= $#arry && $arry[$i] == 0 )
Having said all of that, GrandFather is right. Just use grep.
|
|---|