I have a testing routine which, as part of the test, calls a function in a way that generates a warning message. I am expeting this warning message and would like to supress it in order to have clean test output.
However I only want to supress the warning message for this instance of the function call and I want to keep any other error messages that might occour.
I have tried using the 'no warnings qw/type/' pragma but have run into what seems to be a block nesting problem.
According to
perllexwarn the warnings pragma works on a block level which is fine. My problem seems to be when trying to control runtime warnings the scope doesn't work as I'm expecting:
#!/bin/perl
use warnings::register;
use warnings;
printf( "Perl Version: %vd\n",$^V);
test_warnings();
sub GenerateWarning {
warn "warnings are ",
warnings::enabled() ? "" : "not ",
"enabled\n";
}
sub test_warnings {
no warnings;
GenerateWarning();
AnotherSub();
}
sub AnotherSub {
GenerateWarning();
}
Produces the output:
Perl Version: 5.6.1
warnings are not enabled
warnings are enabled
What I would like is for warnings to be
not enabled both times.
Is there a way to do what I want to do? Should I be doing this a different way?