Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Hash slices ?

by arturo (Vicar)
on Dec 01, 2000 at 18:58 UTC ( #44357=note: print w/ replies, xml ) Need Help??


in reply to Re: Hash slices ?
in thread Hash slices ?

how do I find if at least one of many keys in a list is in a hash (quick, fast, and simple)

Dunno if this meets *all* of your criteria, but I find this simple enough:

my @search_keys = qw(one two three); my %hash = ( four=>4, five=>5, six=>6); my $foundit =0; foreach (@search_keys) { if (exists $hash{$_}) { $foundit =1; print "found an entry for $_ in %hash!\n"; } }

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


Comment on Re: Re: Hash slices ?
Download Code
Re: Re: Re: Hash slices ?
by davorg (Chancellor) on Dec 01, 2000 at 19:06 UTC

    Given that the idea is to find out if any of the keys exist in the hash, it would be more efficient to call last and exit the loop once you've found one.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2014-08-22 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (156 votes), past polls