Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: variable through another variable

by Juerd (Abbot)
on Jan 26, 2002 at 17:01 UTC ( #141776=categorized answer: print w/replies, xml ) Need Help??

Q&A > Data Structures > variable through another variable - Answer contributed by Juerd

That will work, but not under strict 'refs'. Symbolic references are considered bad practice (but you can't always avoid them).

$testing = "Hello, World!\n"; $var = "testing"; $data = $$var; print $data; # prints Hello, World!

Using a hash is better, and hashes are useable under strict 'refs':
$hash{"testing"} = "Hello, World!\n"; $var = "testing"; $data = $hash{$var}; print $data;
(You can remove quotes from hash keys that have no \W characters: $hash{testing}.)

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2021-03-03 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (81 votes). Check out past polls.

    Notices?