dt said:
how do I do this:
convert a string such as "dim1:dim2:dim3"
or array ("dim1", "dim2", "dim3")
to a hash like:
$hash{"dim1"}{"dim2"}{"dim3"}
any help is appreciated
after reading Brians excellent reply
(which was somehow new for me), I'd
like to add 2 "functional forms" to
the discussion (recursive), one
ends up with 'undef' on the chain,
the other with a clean hash ref:
...
# end up w/hash ref:
sub rh2arr { rh2arr($_[0]->{$_[1]}={}, @_[2..@_-1]) if @_>1 }
#end up w/undef
sub rrh2arr { rrh2arr(\${$_[0]}->{$_[1]}, @_[2..@_-1]) if @_>1 }
# usage
my @arr = qw'dim1 dim2 dim3';
my (%hash1, %hash2);
rh2arr \%hash1, @arr;
print Dumper \%hash1;
rrh2arr \\%hash2, @arr; # learned \\this from Brian's post ;-)
print Dumper \%hash2;
...
Regards (and thanks to Brian)
Mirco