in reply to Re: How do I delete a row of an array
in thread How do I delete a row of an array
Is this the reason that delete shouldn't be used and if so what are the specific pitfalls in this?
Well one reason would be that your code would break if you needed it to run on Perl < 5.6. You'd also have to take into account that the element itself does not get removed. A 10 element array is still a 10 element array only now one of the elements has an uninitialized value. If you take that into account in your code you'll be ok.
for my $foo (@array) { next if (! $foo); }
Personally I'd stick with splice as it's more DWIM - remove an element in the middle of an array and the index of the ones after it will now shift down.
|
|---|