in reply to Unique elements in array

Something along the lines
my @set = qw(a a b c c); my %seen; $seen{$_}++ foreach @set; my @unique = grep { $seen{$_} == 1 } @set;
maybe?

Replies are listed 'Best First'.
Re^2: Unique elements in array
by johngg (Canon) on May 09, 2007 at 14:06 UTC
    Your code could be condensed to

    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