pg has asked for the wisdom of the Perl Monks concerning the following question:

Several days ago, when I replied a post about format, I said something like "in the format statement, you declared $a once, later you used 'my' to declare $a again, those two $a's are different, and the first $a is no longer touchable." I suddenly realized this morning that, when the main idea of that statement is correct, that untouchable comment is absolutely wrong.

I apologize. Actually the first $a is still touchable, although you can no longer touch it by name, you still can touch it by ref.
use strict; format Something = @###.## $a . my $ref_old_a = \$a;#this makes the first $a still touchable my $a = 200; #declare the second $a $$ref_old_a = 100;#touch the first one by ref $~ = "Something"; write;#print out 100.00

Replies are listed 'Best First'.
Re: A correction to my earlier comment about format
by mojotoad (Monsignor) on Dec 16, 2002 at 20:27 UTC
    You can also still touch it with a fully qualified name for the package variable:

    use strict; $a = 'woof'; my $a = 'meow'; print "lexical \$a: $a\n"; print "package \$a: $main::a\n";

    Had you used local rather than my, then $a would have been masked in the symbol table -- $main::a would reflect the local value through the rest of the declaration scope, even by reference:

    use strict; $a = 'woof'; $a_ref = \$a; local $a = 'meow'; print "\$a: $a\n"; print "package \$a: $main::a\n"; print "ref to package \$\$a: $$a\n";

    Matt