in reply to Re^2: define a hash-value, using hash-ref and a list of keys
in thread define a hash-value, using hash-ref and a list of keys
You only have an issue if you want to avoid it.
hmm thats the problem if you post from a mobile client without possibility to test...
I'll update a working solution, though using Data::Diver should help already.
--->use warnings; use strict; use Data::Dumper; my @keys="a".."d"; my %hash=(); my $href=\%hash; my $lastkey= pop @keys; for my $key (@keys) { $href = $href->{$key} //= {} ; } $href->{$lastkey} = ""; print Dumper \%hash;
$ perl dive.pl $VAR1 = { 'a' => { 'b' => { 'c' => { 'd' => '' } } } };
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: define a hash-value, using hash-ref and a list of keys
by janssene (Initiate) on Oct 30, 2014 at 10:28 UTC | |
by LanX (Saint) on Oct 30, 2014 at 10:44 UTC |