Piers Cawley wrote:
> If I replace C<< ($key, $val) >> with > > @ary = m/<$pattern>/ > > and the match succeeds, how many elements are there in @ary? Zero. No explicit captures in that pattern. > Suppose you want to use a hypothetical variable to bind a name to > a capture: > > / (\S+) { let $x := $1 } / > > A shorthand for that is: > > / $x:=(\S+) / > > The parens are number independently of any name, so $x is an alias > for $1. > > And it's that last sentence that's important here. So, it looks like > C<< +@ary >> is going to be 4. No. Only explicit paren captures add to the array attribute of the match object. Implicit or explicit named captures add to the *hash* attribute of the match object. > m: w / $2:=(\S+) <lt>= $1:=(\S+) / > > Note that, left to their own devices, those grouping parentheses would > generate the $1 and $2 in the order given. > Now, assignment to hypotheticals doesn't happen all at once, it > happens when the matching engine reaches that point in the > string. Unless I'm very much mistaken, the order of execution will > look like: > > $2:=$1; $1:=$2; > > And it seems to me that we'll end up with $1 and $2 both bound to the > same string; which isn't working quite how I expect. Or do we special > case the occasions when we bind the result of a capturing group to a > numeric match variable? That's my understanding. If you *explicitly* bind a captured group to a numbered hypothetical, then the capture doesn't also implicitly bind to a numbered hypothetical. Damian