Re: perlfaq4: How can I remove duplicate elements from a list or array?
[email protected] (Keith Ivey) Thu, 31 Mar 2005 21:42:41 -0500
| Newsgroups | perl.perlfaq.workers,perl.documentation |
|---|---|
| Message-ID | <[email protected]> |
_brian_d_foy wrote:
> my %hash = map { $_, 1 } @array;
Possibly more idiomatic would be
my %hash = map { $_ => 1 } @array;
> # or a hash slice: @hash{ @array } = ();
> # or a foreach: $hash{$_} foreach ( @array );
That last should be
$hash{$_} = 1 foreach @array;
maybe? As it is, it doesn't create the hash elements.
> The first time the loop
> sees an element, that element has no key in C<%Seen>.
Why the capital "S"? None of the other variables are
capitalized, and it's not standard Perl practice.
--
Keith C. Ivey <[email protected]>
Washington, DC