You didn't change $r the accessed value in your snippet — you changed that which is pointed by $r — so you failed to disprove that $r the accessed value is read-only.
Say you want to do $my_hash_ref->{$k[0]}->{$k[1]}->{$k[2]} = 3;. Compare
use Data::Dumper; my $my_hash_ref = { a => { b => { c => 2 } } }; my @k = qw( a b c ); my $r = $my_hash_ref; $r = $r->{$_} foreach @k; $r = 3; print Dumper($my_hash_ref); # { 'a' => { 'b' => { 'c' => 2 } } };
with
use Data::Dumper; my $my_hash_ref = { a => { b => { c => 2 } } }; my @k = qw( a b c ); my $p = \$my_hash_ref; $p = \($$p->{$_}) foreach @k; $$p = 3; print Dumper($my_hash_ref); # { 'a' => { 'b' => { 'c' => 3 } } };
Update: Fixed a terminology error.
In reply to Re^3: I have a hash in a hash in a .....
by ikegami
in thread I have a hash in a hash in a .....
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |