Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: autovivication and referencing

by thakares (Acolyte)
on Nov 20, 2013 at 16:45 UTC ( #1063554=note: print w/ replies, xml ) Need Help??

in reply to autovivication and referencing

While defining a hash, the key and value pair must be in scalar context.

In your "Scenario 2:", the value of key2 must be scalar and NOT hash. You can use a reference to a hash by replacing paranthesis by a set of curly brackets to define a reference to a hash.

my %hash=( key1 => value, key2 => { param1 => val1, param2 => val2 } );

Scenario 1 seems OK.

Now Autovivification:


$hash{key2}->{param1} now will be val1

It just like JSON of Javascript!

Comment on Re: autovivication and referencing
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-10-13 22:41 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (316 votes), past polls