![]() |
|
more useful options | |
PerlMonks |
comment on |
( #3333=superdoc: 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 reply to Re: Re: Re: Removing Duplicate Array Elements!!!
by gbarr
|
|