Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
No such thing as a small change
 
PerlMonks  

Re: Perl Idioms Explained - keys %{{map{$_=>1}@list}}

by Juerd (Abbot)
on Aug 04, 2003 at 13:02 UTC ( #280660=note: print w/ replies, xml ) Need Help??


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' }


Comment on Re: Perl Idioms Explained - keys %{{map{$_=>1}@list}}
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://280660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (15)
As of 2014-04-18 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls