in reply to Re^2: Rosetta PGA-TRAM
in thread Rosetta PGA-TRAM
Why does the block use $^a in one place (the automatic parameter) and $a in another place? Shouldn't that be a different (undeclared) variable? (Likewise for b).
No, the ^ twigil is only necessary in the first occurrence. That was introduced because things like this:
my $block = { my $v = %hash{$^key}; say "The lookup {%hash{$^key}} yields $v"; };
Would complain about the closure inside the string getting no argument, because $^key was interpreted as a formal parameter to the inner-most closure, which in this case was the one inside the string.
Or more general, you couldn't refer to outer lexicals that happened to be self-declaring formal parameters.
So it was decided that after $^foo occurred once, you could refer to it as $foo to, disambiguating it in inner blocks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Rosetta PGA-TRAM
by John M. Dlugosz (Monsignor) on Jun 17, 2009 at 22:56 UTC |
In Section
Meditations