in reply to Re: Can't remove the the duplicate element when it's the last one in the array
in thread Can't remove the the duplicate element when it's the last one in the array
can be simplified tomy %seen; for ( my $i = 0; $i < scalar @arr; $i++){ splice @arr, $i--, 1 if $seen{$arr[ $i]}++; }
But the following will be much faster:my %seen; for ( my $i = @arr; $i--; ){ splice @arr, $i, 1 if $seen{$arr[$i]}++; }
my %seen; @arr = grep !$seen{$_}++, @arr;
|
|---|