I did notice that Data::Dumper does nearly the same thing you're trying to do ... and I'm trying to figure out how to get Data::Dumper's output to "thaw" back into a usable perl variable. Perhaps someone else will answer this.
The first hash, %h, is what you're trying to do, but in a manner that works. Then I dump it, and I pasted that output back into the code and dump the new hash-ref, $h2. But it doesn't want to work, and I'm not sure what bits of trickery are needed to get it to work - probably some Data::Dumper variables when dumping, but I'm not sure offhand.my $a = [qw{v1 v2}]; my %h = ( k1 => { k11 => $a, k12 => 'w00t!', }, k2 => { k21 => 'what?', k22 => $a, }, ); use Data::Dumper; #print Dumper(\%h); my $h2; $h2 = { 'k2' => { 'k21' => 'what?', 'k22' => [ 'v1', 'v2' ] }, 'k1' => { 'k11' => $h2->{'k2'}{'k22'}, 'k12' => 'w00t!' } }; print Dumper($h2);
In reply to Re: Populating a nested hash with itself?
by Tanktalus
in thread Populating a nested hash with itself?
by jkva
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |