Is there any command to sort an array uniquelly,something similar to
"sort -u" in unix.
Not built-in, but it's fairly easy to implement:
my %h = map { $_ => 1 } @unsorted_with_dups;
my @unsorted_uniques = keys %h;
my @sorted_uniques = sort @unsorted_uniques;
Or, you can remove all the intermediary steps:
my @sorted_unqiques = sort keys(%{{ map { $_ => 1 }
@unsorted_with_dups}});
Here's an example:
$ perl -le'
my @unsorted_with_dups = qw/d a e c b e d a c b e a b c e d/;
my @sorted_uniques = sort keys(%{{ map { $_ => 1 }
@unsorted_with_dups }});
print "@sorted_uniques\n";
'
a b c d e
Paul Lalli