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.
Is this possible, or does the underlying implementation of hypothetical
variables pretty much rule it out?