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); ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Copy an hash modifying some selected values
by Anonymous Monk on Nov 07, 2018 at 18:03 UTC | |
by ikegami (Patriarch) on Nov 07, 2018 at 19:24 UTC | |
by Anonymous Monk on Nov 08, 2018 at 08:36 UTC | |
by ikegami (Patriarch) on Nov 08, 2018 at 10:26 UTC |