Josh Jore wrote:
>>>Would it be correct for this to print 0? Would it be correct for this
>>>to print 2?
>>>
>>> my $n = 0;
>>> "aargh" =~ /a* { $n++ } aargh/;
>>> print $n;
>>
>>Yes. ;-)
>
> Wouldn't that print 2 if $n is lexical
Err. It *is* lexical in this example.
> and 0 if it's localized?
No. Without the C<my> it would still print either 0 or 2, depending
on the implementation/optimization.
> Or are lexicals localized now?
They can be. But this example C<$n> isn't.
(Just because it's used in a nested closure doesn't mean it's
localized within the pattern).
>>>What possible outputs are legal for this:
>>>
>>> "aaa" =~ /( a { print 1 } | a { print 2 })* { print "\n" } x/
>>
>
> I take it that what I've learned from _Mastering_Regular_Expressions_
> doesn't quite apply here? From that interpretation I'd think it'd print
> "111\n" since the second part of the alternation wouldn't be tried.
No. It would fail to match the final C<x> in the pattern and start
backtracking.
Damian