From: Wayne Simmons [mailto:[EMAIL PROTECTED] > > > This is called a "Symbolic Reference". You do it like this: > > > > $database_name = "Greg"; > > $text = "database_name"; > > $value = $$text; > > print $value; > > ok this is kinda freaking me out. I got this to work but I found something > strange. First off you have to do with strict off or perl will complain > (that's not the strange part). However, if you actually declare your > variables with a "my" statement (like a good little programmer) this > doesn't work! my example: > > #!/Perl/bin/perl -w > my ($a,$b,$c) = ('b','test',''); > print "1:$b\n"; > $c = $$a; > print "2:$c\n"; > > In this example, you'll receive no warnings, and you'll see "1:test" so $b > is setting set properly. However, on the second line you'll see "$2:" > indicating that $c did not get the value from $$a. To make it work as > required remove the keyword "my" on the second line: > my ($a,$b,$c) = ('b','test',''); => ($a,$b,$c) = ('b','test',''); > > and now it works! > > Is this because perl is looking somewhere different for the two variables? > Are declared "my" variables different then auto-vivified ones somehow? > Does anyone have some insight into why this would be?
Exactly right. You can't use a symbolic reference to refer to a lexical variable (declared with "my"). Try this code: $test = 'global test'; my $test = 'lexical test'; my $name = 'test'; $result = $$name; print "$result\n"; You'll see that you get the value of the global $test variable as the result. Bowie _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
