in reply to Add distinct elements to an array
But as the list of names gets longer, it will be less efficient. SO use a hash:my @source = qw(bob janne max max bob anne); my @finalnames; foreach $name (@source) { next if(grep(/^$name$/, @finalnames)); push @finalnames, $name; }
my @source = qw(bob janne max max bob anne); my %temphash; my @finalnames; foreach $name (@source) { $temphash{$name} = 1; } @finalnames = (keys %temphash);
|
|---|