develooper Front page | perl.perl6.users | Postings from September 2019

Re: List in regexp

Thread Previous | Thread Next
The Sidhekin
September 3, 2019 12:10
Re: List in regexp
Message ID:
On Tue, Sep 3, 2019 at 8:37 AM yary <> wrote:

> I see.  And that's discussed here (had to really look for it):
>> At first I was looking further down in the "Regex interpolation"
>> section, where it's also touched on, though I kept missing it:
>> > When an array variable is interpolated into a regex, the regex engine
>> handles it like a | alternative of the regex elements (see the
>> documentation on embedded lists, above).
> Which brings up another area for improvement- maybe. A regexp interprets a
> list as alternation only when it's a literal quoted list < like this >, or
> embedded in the regexp as a @-sigilled variable.
> That set up an expectation for me- "oh a list in a regexp becomes an
> alternation of the list elements" - but interpolation meets that
> expectation inconsistently.
> The interpolation doc section states, for both forms of code interpolation
> $(code) and <{code}>, "Runs Perl 6 code inside the regex, and interpolates
> the stringified return value..."

  I missed this the first time (or I would have suggested a version without
the variable), but I think what you want is interpolation by way of @(code).

  eirik@greencat[14:04:06]~$ perl6
You may want to `zef install Readline` or `zef install Linenoise` or use
rlwrap for a line editor

To exit type 'exit' or '^D'
> my $comma-separated='abc,<digit>+';
> say 'abc' ~~ / @( $comma-separated.split(',') ) /;
> eirik@greencat[14:05:48]~$

  I'd argue it's better this way, since syntax has me expecting $(...) to
interpolate a scalar (even if produced from a list), and @(…) to
interpolate a list.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About