In a message dated 7/27/2005 2:31:22 P.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> > 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? > > -Wayne ``my'' variables (lexical variables) do not appear in the symbol table at
run time (as do package variables, whether declared or auto-vivified) and so
cannot be referenced ``symbolically''. lexical variables are dealt
with and disposed of by the compiler at compile time.
btw -- i agree with a previous post that it is better to use a
hash and avoid symbolic references.
bill walters
|
_______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs