in reply to Optimize - Checking multiple occurences of elements in an array
You can use map() to iterate over the array. You can use this to build a hash that has only unique elements:
my @a = (0, 1, 1, 2, 3, 4, 5, 5, 5, 6); my %unique; map { $unique{$_} = 1 } @a; my @a_unique = keys %unique;
Above is untested, as always.
If you want to put the data back in sorted order, change the last line to:
my @a_unique = sort { $a <=> $b } keys %unique;I can't really get more specific without knowing what exactly you are doing, but this should give you some ideas.
|
|---|