Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: Answer: How do I check to see if a value in a hash is equal to something?

by merlyn (Sage)
on May 23, 2000 at 19:47 UTC ( #14391=note: print w/ replies, xml ) Need Help??


in reply to Answer: How do I check to see if a value in a hash is equal to something?
in thread hashes

It has been said:

Another way, of you are only interested in knowing if the value is in the hash, without knowing the key, could be:
$is_in_hash=grep /^Superman$/,values(%hash);
This is not particularly space efficient if the hash is large. See also the second solution suggested in the FAQ mentioned above.
Rather than using a regular expression, just use an ordinary expression:
$is_in_hash = 0 < grep $_ eq "Superman", values %hash;

-- Randal L. Schwartz, Perl hacker


Comment on RE: Answer: How do I check to see if a value in a hash is equal to something?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2014-07-29 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls