It's not clear to me what you are trying to do. After you have traversed the hash refs as you have shown and $nodule has the hash ref of $structure->{stuff}{hierarchy}{album}, then changing $nodule->{$target} will have the effect of changing $structure->{stuff}{hierarchy}{album}{$target}.
Some more code or context would be useful.
YuckFoo
Update: Some code to traverse a list of hash keys and change the last one. HTH.
#!/usr/bin/perl use strict; my ($hash); $hash->{one}{two}{three} = 'before'; print "$hash->{one}{two}{three}\n"; changehash($hash, [qw(one two three)], 'after'); print "$hash->{one}{two}{three}\n"; #----------------------------------------------------------- sub changehash { my ($node, $keys, $val) = @_; my $key; my $last = pop(@{$keys}); for $key (@{$keys}) { if (defined ($node->{$key})) { $node = $node->{$key}; } else { print STDERR "Unknown key: $key\n"; return; } } if (defined ($node->{$last})) { $node->{$last} = $val } else { print STDERR "Unknown key: $last\n"; return; } }
In reply to Re: descending a tree of hash references
by YuckFoo
in thread descending a tree of hash references
by Amoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |