in reply to Adding Unique Elements to Array
my %h; for(qw/foo bar baz quux foo narf bar poit/) { $h{$_} = 1; }
If the order matters, you could keep a separate hash that has all of the items in it as keys.
my (%h, @a); for(qw/foo bar baz quux foo narf bar poit/) { push @a, $_ unless exists $h{$_}; $h{$_} = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding Unique Elements to Array
by ww (Archbishop) on Feb 28, 2005 at 19:57 UTC | |
by friedo (Prior) on Feb 28, 2005 at 20:06 UTC | |
|
Re^2: Adding Unique Elements to Array
by thekestrel (Friar) on Feb 28, 2005 at 18:46 UTC | |
by melora (Scribe) on Feb 28, 2005 at 18:58 UTC |