http://www.perlmonks.org?node_id=1225369


in reply to Copy an hash modifying some selected values

Data::Diver comes in useful here.

use Data::Diver qw( Dive ); my @paths = ('key1', 'key2:key22', 'key2:key23'); for my $path (@paths) { my @path = split(/:/, $path); my $val = Dive(\%hash, map \$_, @path); ... }

It's not that hard to implement yourself, though.

sub dive { my $r = shift; $r = $r->{shift(@_)} while $r && @_; return $r; } my @paths = ('key1', 'key2:key22', 'key2:key23'); for my $path (@paths) { my @path = split(/:/, $path); my $val = dive(\%hash, @path); ... }