Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: What is the best way to find the key is exists or not in a hash ?

by Corion (Patriarch)
on May 10, 2005 at 10:38 UTC ( [id://455507]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    %x = (foo=>1,bar=>2,baz=>3); 
    
    sub exists_srk(\%$){my($h,$k)=@_; map{$_ eq $k?$_:()}(sort reverse key
    +s %$h)};
    
    print exists_srk(%x,$_) for qw(foo bar baz bat)
    
  2. or download this
    sub exists_ggg (\%$) {
      my($h,$k) = @_;
    ...
      grep /^\Q$k\E/ 
      grep { $c++ == 0 } %$h
    };
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-18 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found