Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: variable through another variable

by Juerd (Abbot)
on Jan 26, 2002 at 17:01 UTC ( [id://141776]=note: print w/replies, xml ) Need Help??


in reply to variable through another variable

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://141776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found