The following is the same solution but faster since it eliminates all those slow sub calls:
sub DiveRef { my $p = \shift; $p = \( $$p->{$_} ) for @_; $p } my %myhash; my $ref = DiveRef(\%myhash, qw( bedrock flintstone fred )); -or-- my $myhash; my $ref = DiveRef($myhash, qw( bedrock flintstone fred )); $$ref = 42; # set it to 42 $$ref++; # increment it print $$ref; # print it!
In reply to Re: Recursively walk a hash to get to an element
by ikegami
in thread Recursively walk a hash to get to an element
by merlyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |