Uri Guttman asked:

> now, why does $0.{comment} refer to the internal regex and not the outer
> one? 

Technically, $0 refers to the *match object* of the inner regex, not the inner regex 
itself.


> is it because of it being in the closure?

Yes. And because $0 is lexically scoped.


> could you refer to the outer one from the inner regex?

The outer what? Regex? Match object?

The answer to both is "yes". The (partial) match object of the outer regex becomes the 
topic of the closure, so you refer to it as $_. To refer to the outer regex
you could either name it, and then refer to it by that name, or (possibly) there
will be a C<.self> method on the outer partial match object, so you could refer to the 
outer regex as C<$_.self>.

> 
> also since the comment is optional, if you found a keyword wouldn't that
> try to print an undefined comment resulting in a warning?

Yes. To avoid that, change:

        / <comment>? /

to:

        / [<comment>|$comment:=()] /    # $comment always a (possibly empty) string

or:

        / <comment><0,1> /              # $comment always an array ref

Damian

Reply via email to