my @set = qw(a a b c c); my %seen; my @unique = grep { not $seen{$_} ++ } @set;
That method preserves the order of the original array but if that's not important you could also do
my @set = qw(a a b c c); my %seen; @seen{@set} = (); my @unique = keys %seen;
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^2: Unique elements in array
by johngg
in thread Unique elements in array
by megaurav2002
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |