Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: computed symbol references

by dragonchild (Archbishop)
on Jul 13, 2004 at 13:21 UTC ( #373969=note: print w/ replies, xml ) Need Help??


in reply to computed symbolic references

Your first question is easy to answer.

package x; VERSION = 'bar'; package Foo; VERSION = '1.01'; package main; $bar = '0.01'; $x = 'Foo'; print ${"$x::VERSION"}, $/; print ${$x . "::VERSION"}, $/; ---- 0.01 1.01

The first goes and gets the thing in $x::VERSION (the $VERSION variable in the x:: namespace), then dereferences it as a symbolic reference in the main:: namespace. The second takes the $x variable in the main:: namespace and uses it to create a variable name that is used as a symbolic reference. In this case, the variable $Foo::VERSION.

I'm not sure on the other questions, but you don't have a comma or semi-colon after the ${ ... }. Maybe that's changing your results?

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested


Comment on Re: computed symbol references
Download Code

Log In?
Username:
Password:

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

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

    When choosing user names for websites, I prefer to use:








    Results (213 votes), past polls