in reply to Re^2: I have a hash in a hash in a .....
in thread I have a hash in a hash in a .....
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: I have a hash in a hash in a .....
by brian_d_foy (Abbot) on Feb 21, 2006 at 20:50 UTC | |
by ikegami (Patriarch) on Feb 21, 2006 at 20:57 UTC |