Hope I have my terms correct - I am looking for syntax to manipulate a slice of a hash_ref of a hash_ref. What I want to do is replace the values "a" and "b" with "c" and "d" for KEY11 and KEY12, respectively. The code below is as close as I have come. The print Dumper results follow the code.
#!/usr/bin/perl -w use strict; $href->{KEY1}={KEY11=>"a",KEY12=>"b"}; print 'Initial condition for $href->{KEY1}={KEY11=>"a",KEY12=>"b"}'."\ +n"; print Dumper $href; ${$href->{KEY1}}{KEY11}="c"; print 'Change one key in the hash:${$href->{KEY1}}{KEY11}="c"'."\n"; print Dumper $href; @{$href->{KEY1}}{[qw/KEY11 KEY12/]}=("c" ,"d"); print 'Change all keys in the slice:@{$href->{KEY1}}{[qw/KEY11 KEY12/] +}=("c" ,"d")?'."\n"; print Dumper $href;
Results - Initial condition for $href->{KEY1}={KEY11=>"a",KEY12=>"b"} $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'KEY11' => 'a' } }; Change one key in the hash:${$href->{KEY1}}{KEY11}="c" $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'KEY11' => 'c' } }; Change all keys in the slice:@{$href->{KEY1}}{[qw/KEY11 KEY12/]}=("c" +,"d")? $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'ARRAY(0x50db350)' => 'c', 'KEY11' => 'c' } };
I end up with an anonymous array instead of the slice substitution I was looking for. Any help pointing out the correct syntax would be greatly appreciated.
In reply to HowTo Href_O_Href slice by sgrey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |