Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: hash magic

by sundialsvc4 (Abbot)
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:

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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023476]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2018-05-26 01:12 GMT
Find Nodes?
    Voting Booth?