I'm reading a regular expression from a configuration file, which may or may not have invalid syntax in it. (It's locked down behind a firewall, so let's not get into security.) I've been able to test for a number of errors and give a friendly message.
No such luck on this one:
Unrecognized escape \Q passed through in regex
I know what causes it, I just want to know if I can capture it in Perl 5.8. So far it has resisted my efforts to check for this condition.
So the question is: does anybody know how to capture this? Do I have to redirect STDERR?
You can make the warning FATAL and use block eval:
#!/usr/bin/perl
use strict;
use warnings;
my $s = '\M';
my $r = eval {
use warnings FATAL => qw( regexp );
qr/$s/;
};
$r or die "Runtime regexp compilation produced:\n$@\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With