Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: hash magic

by sundialsvc4 (Monsignor)
on Mar 14, 2013 at 13:30 UTC ( #1023476=note: print w/ replies, xml ) Need Help??


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.™”


Comment on Re: hash magic
Re^2: hash magic
by Anonymous Monk on Mar 14, 2013 at 13:39 UTC

    Perl to the rescue! ...

    That is not Perl, that is English

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2014-07-23 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (152 votes), past polls