in reply to Can't remove the the duplicate element when it's the last one in the array
splice @$arr, --$i, 1 if $seen{$arr->[ $i++]}++;
sub remove_dup { my @arr = (1,1); #,2, 1, 3, 1, 4, 3, 1); my %seen; for ( my $i = 0; $i < scalar @arr; $i++){ splice @arr, $i--, 1 if $seen{$arr[ $i]}++; } print @arr, " "; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't remove the the duplicate element when it's the last one in the array
by ikegami (Patriarch) on Dec 18, 2009 at 16:05 UTC | |
|
Re^2: Can't remove the the duplicate element when it's the last one in the array
by littlehorse (Sexton) on Dec 18, 2009 at 09:15 UTC |