in reply to Recursively walk a hash to get to an element
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Recursively walk a hash to get to an element
by LanX (Saint) on Apr 04, 2021 at 19:20 UTC | |
by ikegami (Patriarch) on Apr 04, 2021 at 19:47 UTC |