in reply to Assigning data to a nested hash with a variable number of levels?
It came to me while I was lying in bed reading a book. Odd how that works.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; }
|
|---|