|There's more than one way to do things|
Re: dynamic hash nestingby moritz (Cardinal)
|on Aug 16, 2012 at 20:45 UTC||Need Help??|
Is this something that is possible in Perl?
The usual strategy to build a data structure of arbitary depth is the "create as you traverse" approach, ie you just walk level by level, create them if needed, and always keep a reference to the previous level to start the current iteration from.
Here you don't even need to do that, because you create at most one level at a time.
Since you didn't explain exactly how the resulting data structure should look like, I've added the description as an extra key called DESCRIPTION.
Without further ado, the code:
Here is the output, with reduced indentation for better readability:
To look up elements of arbitrary depth, you can use something like
Which again drags a reference from the lookup of the previous level to achieve arbitrary depth.