If I were going to, I might do it something like this:
$ perl tuv.pl $VAR1 = { 'a' => { 'b' => { 'c' => 42 } }, 'abc' => { 'def' => { 'ghi' => { 'jkl' => { 'xyz' => 'value' } } } }, 'shock' => 'jock', 'x' => { 'y' => { 'z' => 69 } } }; Roboticus@Waubli ~ $ cat tuv.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; sub set_hash { my $hr = shift; my $val = shift; my $last_key = pop; while (@_) { my $key = shift; $hr->{$key} = {} if ! exists $hr->{$key}; $hr = $hr->{$key}; } $hr->{$last_key} = $val; } my %h; set_hash(\%h, 42, 'a', 'b', 'c'); set_hash(\%h, 69, 'x', 'y', 'z'); set_hash(\%h, 'jock', 'shock'); set_hash(\%h, 'value', 'abc', 'def', 'ghi', 'jkl', 'xyz'); print Dumper(\%h);
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Setting a multi-dimensional hash value
by roboticus
in thread Setting a multi-dimensional hash value
by eyepopslikeamosquito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |