in reply to Extracting unique elements from array
Since you didn't say you needed to sort anything, I'm not sure what use you'd have for cmp and the special $a and $b variables. Finding unique values is straightforward enough: assign them to a hash as its keys, and then extract the keys. Since hash keys are guaranteed to be unique, any assigned multiple times will still only exist once.
my @list = qw(a b c d e a a b c d f g); # list with some duplicates my %h; map { $h{$_} = 1 } @list; print for sort keys %h; # sorting for clarity's sake #output abcdefg
|
|---|