I need to convert a flat list of keys into a nested hash, as follow:
my $hash = {};
my @array = qw(key1 key2 lastKey Value);
ToNestedHash($hash, @array);
Would do this:
$hash{‘key1’}{‘key2’}{‘lastKey’} = “Value”;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Explanation:
We know:
my $h = {}; my $a = [];).It might be more explicit to do this:
But owing to repeated use of these reference idioms, I wrote that line totally as it was and tested it before posting, without error.
As for alternatives, the following version is “easier” (to think up)
But about 6-7 times slower.