What Zaxo doesn't provide, is a working example. So, here is one, tailored to your snippet:
$re = '[\w-]';
my @warnings;
{
local $SIG{__WARN__} = sub { push @warnings, shift };
eval {'' =~ /$re/ };
}
if($@) {
print "error: $@\n";
} else {
foreach my $warning (@warnings) {
print "Got a warning: $warning";
}
}
Alternatively, you can do your checking inside the $SIG{__WARN__} sub.
Note how you need a semicolon after some "blocks" for it to work: after the assignment of the anonymous sub to $SIG{__WARN__}, and after the eval block, at least if any statement comes right after it — which you forgot. |