On Tue, May 17, 2005 at 03:02:12PM -0400, Mark Reed wrote: > > > > On 2005-05-17 14:14, "Peter Haworth" <[EMAIL PROTECTED]> wrote:\ > > > > Does numbering of captures after an alternation continue as if the > > alternative with the most captures matched? > > > > # $1 $1 $2 $3, even if (a) matched > > rx/ [ (a) | (b) (c) ] (d) /; > > I thought that was still like Perl5: > > > # $1 $2 $3 $4 > > rx/ [ (a) | (b) (c) ] (d) /; > > The *numbering* is based on the regex; the *values* are based on the actual > match.
Nope. See the section entitled "Subpattern numbering" in http://groups-beta.google.com/group/perl.perl6.language/msg/2a4b1117301c62b4?hl=en To quote: Specifically, there are significant advantages to numbering the subpatterns in each branch of an alternation (i.e. oneither side of a C<|>) independently, restarting the numbering at the beginning of each branch. And this is precisely what Perl 6 does: # Perl 6... # $1 $2 $3 $4 $5 $6 $tune_up6 = rx/ (don't) (ray) (me) (for) (solar tea), (d'oh!) # $1 $2 $3 $4 $5 | (every) (green) (BEM) (devours) (faces) /; In other words, unlike in Perl 5, in Perl 6 $1 doesn't represent the capture made by the first subpattern that appears in the rule; it represents the capture made by the first subpattern of whichever alternative actually matched. Although last I heard, Larry had agreed to make the first captured paren be $0 rather than $1 so that it could correspond to the indexing of the match object when used as an array. > What's changed in the Perl6 design, AIUI, is nested captures. Given this: > > > rx/ (a (b (c d) e) f) / > > In Perl5, $1 is "abcdef", $2 is "bcde", and $3 is "cd". In the proposed > Perl6 model, there is no $2, just $1 (an object which stringifies to > "abcdef", $1.1 (an object which stringifies to "bcde"), and $1.1.1 (an > object which stringifies to "cd". Yep. Assuming the $1.1 syntax works. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]