On 27 Aug 2002, Aaron Sherman wrote: : I just wrote this code in Perl5: : : $stuff = (defined($1)?$1:$2) if /^\s*(?:"(.*?)"|(\S+))/; : : This is a common practice for me when I parse configuration and data : files whose formats I define. It's nice to be able to quote fields that : have spaces, and this is an easy way to parse the result. : : In Perl6, it looks like what I would like here is very close, but I'm : not sure. Certainly, I could do: : : $stuff = ($1 // $2) if m{^\s*["(.*?)"|(\S+)]}; : : But I would far prefer: : : $stuff = $field if m{^\s*[ : "(.*?)" {let $field=$1} | : (\S+) {let $field=$2}]}; : : even though it's longer.
That seems like a lot of extra work. I'd prefer to see something like: my stuff; m{^\s*[ "$stuff:=(.*?)" | $stuff:=(\S+) ]}; : Is this possible, or does the underlying implementation of hypothetical : variables pretty much rule it out? I don't see any particular reason why a top-level regex can't refer to variables in the surrounding scope, either by default, or via a :modifier of some sort. It's only down in the sub-rules that we have to make sure there's a hash to poke such hypotheticals into. Larry