Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Check if hash key value pair is defined

by davido (Archbishop)
on Nov 15, 2012 at 07:10 UTC ( #1003943=note: print w/replies, xml ) Need Help??


in reply to Check if hash key value pair is defined

Keys in hashes are unique. The only way for a key to have multiple values is if the "value" is a reference to some container (an anonymous hash, anonymous array, or some object). Let's say your hash holds references to arrays. You might do this:

my %hash = ( unwanted => [1], wanted => [2, 3, 4] ); my $target_key = 'wanted'; if( exists $hash{ $target_key } && ref $hash{ $target_key } eq 'ARRAY' && @{ $hash{ $target_key } } > 1 ) { print "The element associated with $target_key holds a reference t +o an array of @{$hash{$target_key}} values.\n"; }

Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003943]
help
Chatterbox?
[MidLifeXis]: Weird - my team is receiving a request for information barely related to a project we are on, asking for information already available to the user from a corporate data source, which happens to be the same source we would use.
[MidLifeXis]: It seems like the requester believes that we have some magic 8 ball source of info that he doesn't have access to.
[GotToBTru]: heh

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-01-20 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (176 votes). Check out past polls.