my $hashref = {}; my $ref = \$hashref; for (@foo) { $ref = \$$ref->{$_}; } $$ref = 1; # or the value you want it to be print Dumper $hashref;
update: this also works if you want to insert more than one array, while the backwards approach will likely destroy previously built data structures
In reply to Re: Array to nested hash
by tinita
in thread Array to nested hash
by amw1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |