in reply to Re: Dynamic addressing in a hash
in thread Dynamic addressing in a hash
DB<44> sub js :lvalue { my $last = pop; my $walk = $js; $walk = $wal +k->{$_} for @_; $walk->{$last} } DB<45> say js(split /-/,"hoig-boig-loig-shmoig") 666 DB<46> say js(split /-/,"hoig-boig-loig-shmoig") = 42 42 DB<47> say js(split /-/,"hoig-boig-loig-shmoig") 42 DB<48> x $js 0 HASH(0x337b528) 'hoig' => HASH(0x337b768) 'boig' => HASH(0x337b498) 'loig' => HASH(0x3379e08) 'shmoig' => 42 DB<49>
see also Data::Diver for more elaborated handling of edge cases
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|