littlehorse has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE:
I have figured out what's the problem, I was using qw{1, 1} to construct the array, then the first element is "1," and the other one is "1", thanks for your attention, embarrassing...
I encountered a subroutine like the following:sub remove_dup { my @arr = shift; my %seen; for ( my $i = 0; $i <= $#{$arr}; ){ splice @$arr, --$i, 1 if $seen{$arr->[ $i++]}++; } }
It intended to remove the duplicated elements in the array, but when the element is the last one in the array, it can't be removed?
just like {1,1} can't be changed to {1}, but {1,1,2} will be changed to {1,2}.
Can anyone give a hint?
|
|---|