A string used in a regex is used as a regular expression.
I guess you've understood this, but your attempt to escape the star didn't work:
$ perl -wE 'say "\*E"'
*E
The double-quoted string ate the backslash, the regex just sees *E.
There are several solutions:
# ugly, but works:
my $failmsg = "\\*E";
if (/$failmsg/) { ... }
# nicer, since you don't have to do the escaping yourself
$failmsg = '*E';
if (/\Q$failmsg\E/) { ... }
# if you want to quote regular expressions, do this:
$failmsg = qr{\*E};
if ($_ =~ $failmsg) { ... }
This last solution is nice because it accepts modifiers, so for example if you want to do a case-insensitive match, you can write $failmsg = qr{\*E}i;.
Perl 6 - links to (nearly) everything that is Perl 6.
|