|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
Re: Re: Re: Removing Duplicate Array Elements!!!by gbarr (Monk) |
| on Sep 27, 2001 at 19:45 UTC ( #115125=note: print w/ replies, xml ) | Need Help?? |
|
If you are looking an efficient method to do this then try.
my %hash;
@hash{@a} = ();
@a = keys %hash;
But that only works, just as your example, for non-references as the keys of a hash can only be strings. If @a may contain references that you want to preserve then use
my %hash;
@hash{@a} = @a;
@a = values %hash;
This is slightly less efficient as it causes an extra copy of each element in @a I generally write this as
@a = do { my %h; @h{@a} = @a; values %h }; # unique
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||