in reply to Re: Copy an hash modifying some selected values
in thread Copy an hash modifying some selected values
is:use strict; use Data::Dumper; my %hash1 = ( key1 => 'relative_path', key2 => { key21 => 'another_relative_path', key22 => '/an_absolute_path', key23 => 'relative_path', }, key3 => '', key4 => 4 ); my @paths = ('key1', 'key2:key22', 'key2:key23'); for my $path (@paths) { my @path = split(/:/, $path); my $val = dive(\%hash1, @path); warn $val; } sub dive { my $r = shift; $r = $r->{shift(@_)} while $r && @_; return $r; }
So I can get the values of interest to be checked, but how do I set them in the new %hash2?relative_path at test2.pl line 20. /an_absolute_path at test2.pl line 20. relative_path at test2.pl line 20.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Copy an hash modifying some selected values
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 |