Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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!

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 making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2016-07-29 21:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (264 votes). Check out past polls.