On Sun, Jan 27, 2002 at 10:43:08PM -0000, Rafael Garcia-Suarez wrote:
> Melvin Smith wrote in perl6-language:
> >>
> >>Besides no one has commented on Steve Fink's (I think it was him) idea
> >>to store the result of the most recently executed conditional in $?. I
> >>kinda like that idea myself. It makes mnemonic sense.
> >
> > I like the $? idea, and it could probably be optimized away.
>
> And $? should probably be automatically temporarized to the current
> block (a bit like $^H in Perl 5) :
>
> if foo() {
> if bar() {
> # $? is bar() here
> frob(); # let's call a function that may contain
> # if statements
> }
> # but $? is foo() here
> }
>
> (is "temporarized" the correct word, now that local() goes away?)
No, certainly not. It should be lexically scoped.
do { my $a = 3; do { my $a = 4; }; print $a };
prints 3 (you don't need to do anything fancy like temping to make the
outer $a's scope extend past the end of nested blocks.) But we do not want
sub p { print $? }
if ($x == 3) { p() }
to print 3. That introduces the same headaches as the non-lexical $_ does now.