in reply to Populating a nested hash with itself?
It doesn't work because there isn't anything in %hash (or %$hashref) at the time $hashref->{key1}{key1_1} is evaluated. The assignent of the list to %hash (and therefore to %$hashref) only happens when the ")" is reached. The following would work:
my %hash; my $hashref = \%hash; $hash{key1} = { key1_1 = ["value1_1",value1_2"], key1_2 = "w00t!", }; $hash{key2} = { key2_1 = "wakkawak!", key2_2 = $hashref->{key1}{key1_1}, };
so would:
my $it = ["value1_1",value1_2"]; my %hash = ( key1 => { key1_1 = $it, key1_2 = "w00t!", }, key2 => { key2_1 = "wakkawak!", key2_2 = $it, }, ); my $hashref = \%hash;
|
|---|