Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: exists() unexpected behavior

by MrNobo1024 (Hermit)
on Apr 12, 2001 at 05:16 UTC ( [id://71916]=note: print w/replies, xml ) Need Help??


in reply to exists() unexpected behavior

When you access part of a multidimentional hash, even if you're only using exists(), it creates all the keys except the last one. So if you call exists $foo{'bar'}{'baz'}{'qux'}, it creates $foo{'bar'} and $foo{'bar'}{'baz'}, but not $foo{'bar'}{'baz'}{'qux'}.

If you don't want that to happen, you have to test every level, starting with the top:

if(exists $foo{'bar'} and exists $foo{'bar'}{'baz'} and exists $foo{'b +ar'}{'baz'}{'qux'}) { ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found