Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: storing and using LoL pathby almut (Canon) |
on May 26, 2007 at 02:03 UTC ( [id://617646]=note: print w/replies, xml ) | Need Help?? |
The closest I want to accomplish is the this example u shown :
In what way does this not do what you described? Well, another way would be to store the "XPath" as a string in the hash, and then eval it at runtime, i.e.
With the example data from my previous post, this would also print
In other words, you construct snippets of literal Perl source (e.g. "\$lol->$xpath", interpolating to '$lol->{key1}[3]{key2}'), which you then eval. Thing is that the XPath thing would need to be turned into runnable code — either at compile-time (like in the function dispatcher approach shown first), or with an eval at runtime. Expect a performance penalty though, if you call the eval many many times... (Update: not to mention that using eval would require some awareness of security issues, if you apply it in scenarios where the code being constructed dynamically is potentially coming from insecure sources)
In Section
Seekers of Perl Wisdom
|
|