On Mon, 18 Sep 2017 09:00:54 -0700, c...@zoffix.com wrote:
> IRC: https://irclog.perlgeek.de/perl6/2017-09-18#i_15181575
> 
> We can use $0 here to refer to previous capture and regex matches:
>     m: say "11" ~~ /(\d)[$0]/
>     rakudo-moar 48a84d: OUTPUT: «「11」␤ 0 => 「1」␤»
> 
> But if we capture that match, the match fails:
>     m: say "11" ~~ /(\d)([$0])/
>     rakudo-moar 48a84d: OUTPUT: «Nil␤»

Not a bug.

Each `( )` capture represents a subpattern¹ that builds its own Match object, 
and inside the subpattern, `$/` refers to this subpattern's Match (which in 
your case doesn't have any captures) and not to the parent pattern's Match 
(which has the capture you meant to access).
(PS: Remember that `$0` is just an alias for `$/[0]`.)

I don't think there's a built-in way to access a parent pattern's Match object 
- you'll have to manually pass on the object in a variable or similar, like you 
already discovered in the linked IRC log.

This ticket can IMO be closed as 'rejected', but I'll leave it open for now in 
case I missed something obvious or in case you want to turn it into an RFC or 
similar.


---
[1] http://design.perl6.org/S05.html#Subpattern_captures

Reply via email to