On Wed, 18 Sep 2002, Luke Palmer wrote:
> On Wed, 18 Sep 2002, Josh Jore wrote:
> > On Wed, 18 Sep 2002, Damian Conway wrote:
> > > > 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.
>
> The first time through, yes. But then it tries to match the "x", and says
> "oops, that's not what I have" and backtracks. That tries the second of
> the alternation, which doesn't work either. So it backtracks so the * is
> only getting two of the first one, et cetera...
>
> Or are you talking about something else from Mastering Regular
> Expressions? Like some kind of optimization that happens?
I missed the trailing 'x/' since my perl5 eyes read that as '/x'. My bad.
Joshua b. Jore -{ weird geeky madness }-> http://www.greentechnologist.org