Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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:

Values:

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

It just like JSON of Javascript!


Comment on Re: autovivication and referencing
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-10-31 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls