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!
|
---|
In Section
Seekers of Perl Wisdom