http://qs321.pair.com?node_id=1077442


in reply to Create unique array --the hard way!

How about losing the duplicates while sorting? Here is the quicksort implementation from Rosetta Code:

sub quick_sort { my @a = @_; return @a if @a < 2; my $p = pop @a; quick_sort(grep $_ < $p, @a), $p, quick_sort(grep $_ >= $p, @a); } my @a = (4, 65, 2, -31, 0, 99, 83, 782, 1); @a = quick_sort @a; print "@a\n";

(This is for sorting numbers.) If you now replace >= with > so you get

quick_sort(grep $_ < $p, @a), $p, quick_sort(grep $_ > $p, @a);

you will get a sorted array without duplicates.