http://www.perlmonks.org?node_id=469429


in reply to Re: One line assigment statement with regex match
in thread One line assigment statement with regex match

I get search pattern not terminated when I try this:
my $re = qr/(?:${\( join "|", map { qr/\Q$_\E/ } @terms )})/;

Replies are listed 'Best First'.
Re^3: One line assigment statement with regex match
by mugwumpjism (Hermit) on Jul 06, 2005 at 22:07 UTC

    Terribly sorry, I didn't test it.

    Yes, the double use of "/" to delimit regular expressions is tripping up the parser. Much better to use braces;

    @terms=qw(foo bar b.*az); my $re = qr{(?:${\( join "|", map { qr{\Q$_\E} } @terms )})}; print "$re\n";

    The above will print "(?-xism:(?:(?-xism:foo)|(?-xism:bar)|(?-xism:b\.\*az)))"

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";