http://www.perlmonks.org?node_id=1023476


in reply to hash magic

Perl to the rescue!   Read up on the topic of auto-vivification, which is a fancy-pants way of saying that something “just springs to life automatically.”   Hash structures of fairly arbitrary complexity can be fairly instantly built that way.

For example, consider:
$foo->{"1"}->{"a"}->{3}->{"foobar"}++;

Without you doing anything out-of-the-way at all, $foo will become a hashref and, just like that, it will have a key 1 which contains a hashref with a key a ... and so on ... and at the tail of the thing will be the number 1, filed under foobar, because that key sprang into existence with the value zero (which is what it needs to be because it’s about to be incremented), which got incremented by the ++ operator.   If you execute the statement again, well, the entire data structure already exists, and now the value at the tail of it is 2.

If that ain’t magic, I don’t know what is.   You will just need to craft a regular-expression to pull the string apart, then you can just write the one statement to create the entire data structure, and it will “just work.™”