in reply to Assigning data to a nested hash with a variable number of levels?

The module solution would probably work fine (assuming my client can figure out how to install the proper module), but the other post seems a bit confusing. It doesn't matter though - I finally figured out how to do it properly with references (or is it pointers?):
use strict; use warnings; my %hash; assign(\%hash, 'aa', 'bb', 'cc', 'value'); print $hash{aa}{bb}{cc}; sub assign { my $p = shift; my $val = pop; my $last = pop; for (@_) { $p->{$_} = {} if !$p->{$_}; $p = $p->{$_}; } $p->{$last} = $val; }
It came to me while I was lying in bed reading a book. Odd how that works.
  • Comment on Re: Assigning data to a nested hash with a variable number of levels?
  • Download Code