Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: keys %{$hash->{$href}} adds $href to the hash if it doesnt exist?

by haukex (Archbishop)
on Nov 17, 2017 at 09:42 UTC ( [id://1203651]=note: print w/replies, xml ) Need Help??


in reply to keys %{$hash->{$href}} adds $href to the hash if it doesnt exist?

This is "autovivification" and was just discussed the other day, see the replies in the thread Array dereference in foreach(), including the ones deeper down in the thread.

Use exists to check if a hash key exists. As described in its documentation, if you have multi-level data structures (hashes of hashes), you need to check every level. Update: Discipulus just updated to show an example.

  • Comment on Re: keys %{$hash->{$href}} adds $href to the hash if it doesnt exist?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found