Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: Variable Names and References

by rvosa (Curate)
on Mar 12, 2007 at 00:52 UTC ( #604266=note: print w/replies, xml ) Need Help??

in reply to Re: Variable Names and References
in thread Variable Names and References

# or: my $ref = "str$_"; # this is a purely symbolic reference, +access is the same as above
I don't see how that is a symbolic reference? I think this is (had to think a while to come up with something contrived, here):
my $class = 'CGI'; my $version; { no strict 'refs'; $version = ${"${class}::VERSION"}; use strict; } print $version # e.g. 3.05 on my machine
In other words, we construct a variable's name ($CGI::VERSION) out of expanded variables ($class), and expand (it's almost like a string eval()) the result in turn to return the value stored under the constructed variable's name.

...mmmm still not really put elegantly, sorry.

Replies are listed 'Best First'.
Re^3: Variable Names and References
by Joost (Canon) on Mar 12, 2007 at 10:25 UTC
    Symbolic references are just names of global variables. That means "str2" is a symolic reference, just like "CGI::VERSION" is.

    In other words; "${class}::VERSION"; is a symbolic reference, and ${"${class}::VERSION"}; derefences the reference into the value of $CGI::VERSION. Note that "hard" references use exactly the same syntax to dereference.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-11-26 01:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found