Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Dereferencing simple variable

by akho (Hermit)
on Apr 01, 2009 at 13:45 UTC ( #754702=note: print w/ replies, xml ) Need Help??

in reply to Dereferencing simple variable

It looks like you are trying to use variable names stored in strings? This is not a very good thing to do, and you should probably reconsider.

However if you insist on doing that, you should look into symbolic references (see perlref). They only work with package variables, however (not those created with my). This seems to work:

my $test = "help"; our $help = 1; no strict 'refs'; if(defined($$test)){ print "defined\n"; };

Comment on Re: Dereferencing simple variable
Select or Download Code
Replies are listed 'Best First'.
Re^2: Dereferencing simple variable
by chrishowe (Acolyte) on Apr 01, 2009 at 14:03 UTC
    I'm going to try and reconsider. As above, hashes are most proably the way forward!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2015-10-09 10:44 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (238 votes), past polls