I have recently run into a situation I found odd and thought perhaps those monks with some greater inner vision than myself could shed some light.
I have the following per program:
#! /usr/bin/perl
my $A='B';
my $B=7;
my $C=${$A};
print "A = $A - B = $B - C = $C\n";
The output of this snippet is this:
A = B - B = 7 - C =
I expected to see 7. It seems as though $c is empty in this case. I did not expect this at all as all of the variables are declared in the same scope. Thinking I was perhaps a little crazy and certianly understanding less perl than I should I embarked upon a solution to this problem. I did eventually came up with this:
#! /usr/bin/perl
my $A='B';
local $B=7;
my $C=${$A};
print "A = $A - B = $B - C = $C\n";
As expected the output is:
A = B - B = 7 - C = 7
Also of note, is that declaring all the variables as local or not declaring any of them with local or my works as expected. I understand vaguely the difference between my and local but the explanation for why all variables declared as my would fail this simple test.
Did I stumble across a defect?
Is this something I should not have done in Perl?
Please enlighten a lost soul.
Sincerely,
Akira