I've been searching for how to parse a string into a regex, like qr/$str/
does in Perl 5, but so far without success.

At first I assumed, by analogy with .Str, .List, etc, that I could call
.Regex on a string, but this is not the case.

On IRC's #perl6 I learned about the <$str> construct, which doesn't really
create a new regex, but keeps a reference to the string around, with some
(to me) surprising semantics:

my $str = 'foo';
my $re = rx/<$str>/;
$str = 'bar';
'foo' ~~ $re;  # no match

Still, it's *almost* sufficient for my needs, except that for the purposes
of a golfing challenge I'm working on, I want to parse the argument to a
WhateverCode object into a regex, but this:

map rx/<*>/, <a b c>;

...rather predictably doesn't work.

So, is there in fact any way to simply parse a string into a brand-new
Regex object?

Reply via email to