On 04/12/2017 04:08 PM, Илья Рассадин wrote:
Hi!
You can use splice to delete elements from array.
To delete multiple elements you need to do splice in a loop
my @indices = qw/2 4 5 7/;
why are you using qw which makes strings and not a list of integers?
my @array;
for my $index (reverse sort @indices) {
sort defaults to a lexical sort which won't work well on integers with
more than 2 digits.
and why are you sorting and reversing the indexes? i don't think that
will help make the splice more efficient if any of the indexes are not
at the end of the array.
splice @array, $index, 0;
you need a length of 1 to remove the element. that line is a no-op.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/