http://www.perlmonks.org?node_id=280660


in reply to Perl Idioms Explained - keys %{{map{$_=>1}@list}}

In the same category, to see if $bar is in @foo:

my %foo = map { $_ => 1 } @foo; if ($foo{$bar}) { ... }
or faster and using less memory:
my %foo; undef @foo{@foo}; if (exists $foo{$bar}) { ... }

Of course, for a single test, grep is easier and often faster:

if (grep $_ eq $bar, @foo) { ... }

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }