How can I use the value of a variable as a variable name in Perl?
问题 If I have a variable, $bar , which is equal to string "foo" and $foo is equal to 0xdead , how can I get $foo 's value while I only have the the string for the variable name? Essentially, I want to do a kind of pointer indirection on the global namespace or a hash lookup on the global namespace. The following didn't work: perl -e 'my $foo=0xdead; my $bar ="foo"; print ${$bar}."\n";' It only prints the newline. 回答1: This trick works only with global variables (symbolic references seek the