in reply to Re: How I learned to stop worrying and love the hash slice. (boo)
in thread beyond me
Assuming you wanted to keep the first occurance, this will preserve the original order.my @a = (1,2,3,2,1); my %seen; my @unique_a = grep {!$seen{$_}++} @a; print "A: $_\n" for (@a); print "Unique: $_\n" for (@unique_a);
Or you can use map to create your %a hash.
my @a = (1,2,3,2,1); my %a = map {$_=>1} @a; my @unique_a = keys %a; print "A: $_\n" for (@a); print "Unique: $_\n" for (@unique_a);
-Blake
|
|---|