in reply to Perl Anomaly

  1. Variables declared with my are lexical variables. As such, they are not put into the package's symbol table.
  2. The syntax $y = 'z'; $x = ${$y}; is an example of using a soft reference. Aside from the fact that you shouldn't use them (instead, use hashes), this looks the variable name up in the package's symbol table.
  3. Since $B in your first example is a lexical variable, it cannot be found with the soft reference.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: Perl Anomaly
by Akira71 (Scribe) on Jan 14, 2005 at 16:14 UTC
    Thank you veyr much for the simple and understood answer. It makes much sense to me now. I did not think I should use it that way, but once I stumbled onto the issue I wished to pursue it to a greater depth.

    Sincerely,

    Akira
Re^2: Perl Anomaly
by Akira71 (Scribe) on Jan 14, 2005 at 17:51 UTC
    Just as a side note, I decided to force the variable $c into the symbol table using use vars qw{$c}; and then the use of my works in the first case.

    Not practicle, but enjoyable to look into.
      and then the use of my works in the first case.
      This seems unlikely. What happens when you declare a variable with "our" or "use vars" and then declare it again with "my" is that the second one essentially replaces the first one for the remainder of that scope. So if you refer to the variable through a sympolic reference, you get the global one, but if you refer to it directly you get the lexical one. For example,
      use vars qw($B); my $A='B'; my $B=7; my $C=${$A}; print "A = $A - B = $B - C = $C\n";
      prints "A = B - B = 7 - C =" This happens because no value is ever assigned to the global variable called $B. Wacky, huh?