On Tue, Apr 14, 2015 at 08:58:27PM -0400, Nathan Gray wrote:
> I've run into a snag, in that my strptime processing in Perl 5
> relies on building a string that looks like a regex with named
> captures, and then interpolating that into a real regex.
>[...]
>     my $pattern = Q/$<greeting>=[hello]/;
>     my $string = Q/hello/;
>[...]

Just an idea: instead of building strings to be interpolated into 
a regex, could you just build regexes directly?

    my $pattern = rx/$<greeting>=[hello]/;
    my $match = "hello" ~~ / <pattern=$pattern> /;

The resulting string is captured into $match<pattern><greeting>;
The second statement can also be written as:

    # captures into $match<pattern><greeting>
    my $match = "hello" ~~ / $<pattern>=$pattern /;
   
    # captures into $match[0]<greeting>
    my $match = "hello" ~~ / $<0>=$pattern /;   
 
Hope this is useful, or at least illustrative.

> Of course, there may be a better way, since regex interpolation
> seems frowned upon in Perl 6.

I think it's more that we treat regexes as first class components (actually
closures)...  rather than EVALing strings with metacharacters, we just 
build regex expressions and interpolate them directly.

Pm

Reply via email to