faqts : Computers : Programming : Languages : Perl : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 7 of 8 people (88%) answered Yes

Entry

How can I create a variable named $foo from the variable $tmp="foo"?

Oct 23rd, 2003 05:53
Colin Thomsen, Phil S., fabrizio vanzani,


You can do this by useing multilevel data structures.
An example would be:
$tmp="foo"
${$tmp} = "newdata";
You can also use:
$tmp="foo"
${"$tmp"} = "newdata";
Note by Colin Thomsen:
You can also do:
$tmp = "foo";
$$tmp = "newdata";
print "$foo\n";
This shows that $$tmp is equivalent to $foo