Hi Perlmonks,
Is if possible to have a string interpreted as a literal without pre-escapting in a regex. Consider:
#!/opt/local/bin/perl
my $a = "Tick F***ing Tock";
my $b = "Friday night at 11:30pm the start of a new series, 'Tick F***
+ing Tock' explores...";
if ($b =~ /$a/)
{
print "..do something..\n";
}
This will return:
$ ./t.pl
Nested quantifiers in regex; marked by <-- HERE in m/Tick F** <-- HERE
+ *ing Tock/ at ./t.pl line 5.
Of course this will work:
#!/opt/local/bin/perl
my $a = "Tick F***ing Tock";
my $b = "Friday night at 11:30pm the start of a new series, 'Tick F***
+ing Tock' explores...";
$a =~ s/([\(\)\[\]\{\}\\\*\?\.\$\^\@\!\&])/\\$1/g;
if ($b =~ /$a/)
{
print "..do something..\n";
}
Result:
$ ./t.pl
..do something..
However there will result in a long list of escapes to make parsing safe as '$a' in my script is dynamic and not fixed like in this example... Also there will no doubt be a significant performance hit considering the number of times I'd be looping over the regex...
Thanks in advance.