Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-02-22 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (326 votes). Check out past polls.