On 31 Aug 2002 at 0:17, Piers Cawley wrote: > my $pattern = rx:w / $1:=(\S+) =<gt> $2:=(\S+) | > $2:=(\S+) <lt>= $1:=(\S+) /; > > @ary = m/<$pattern>/ > > how many elements are there in @ary? I can > make a case for 4 quite happily. Certainly that's what A5 seems to > imply: > > 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.
How could it be 4? If the example would've been > my $pattern = rx:w / $a:=(\S+) =<gt> $b:=(\S+) | > $b:=(\S+) <lt>= $a:=(\S+) /; Then there is 4 variables to speak of ($1,$2,$a,$b) and a question arises about which of these are returned. In the original example however we only have 2 variables ($1,$2) so it can't really return anything else than those 2. > m: w / $2:=(\S+) <lt>= $1:=(\S+) / > > 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? As I understand it, binding to $1 etc.. is a special case. Also I don't see any problems in your example: m: w / $2:=(\S+) <lt>= $1:=(\S+) / First () is captured and assigned to $2 (instead of $1). Then second () is captured and assigned to $1. -- Markus Laire 'malaire' <[EMAIL PROTECTED]>