Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Heisenberg Uncertainty Hash

by Anonymous Monk
on Apr 27, 2005 at 09:04 UTC ( [id://451869]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Heisenberg Uncertainty Hash
in thread Heisenberg Uncertainty Hash

Putting an exists there, (exists $hash{'d'}->{'value'}) still autovivificates $hash{'d'}. This might be surprising, but it is logical. After all, you are enquiring about the hash %{$hash{'d'}} (asking whether it contains the key 'd'). Since that hash doesn't exists yet, Perl does what it always does in that case: it creates it.

If you want to cover all your bases, and make sure no hash gets created as a side effect, be more explicite:

if (exists $hash{'d'} && ref $hash{'d'} eq "HASH" && exists $hash{ +'d'}->{value}) { ... }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found