[tpm] Breaking a string up into hash keys
Antonio Sun
antoniosun at lavabit.com
Sat Apr 13 07:33:27 PDT 2013
On Sat, Apr 13, 2013 at 1:29 AM, Digimer <lists at alteeve.ca> wrote:
> Hi all,
>
> I've got a rather large, random-depth hash. ie:
>
> $conf->{foo}{bar} = "a";
> $conf->{baz} = "1";
> $conf->{this}{and}{the}{other}**{thing} = "what?";
>
> And so on. The number of hash keys can be quite varied, depending on the
> use.
>
> So now I want to be able to take a string that is in the format:
>
> foo::bar
> baz
> this::and::the::other::thing
>
> Split on the :: and use that to pull the value out of the hash.
>
Use eval.
It's pretty simple to transform "this::and::the::other::thing"
into {this}{and}{the}{other}{thing}, and the next thing is to pull the
value out of the hash:
$ perl -d -e 0
DB<5> eval '$conf->{foo}{bar} = "a";'
DB<6> p $conf->{foo}{bar}
a
HTH
Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130413/e1d06e5a/attachment.html>
More information about the toronto-pm
mailing list