kryten has asked for the wisdom of the Perl Monks concerning the following question:
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:
Produces the output:#!/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(); }
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?Perl Version: 5.6.1 warnings are not enabled warnings are enabled
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Nested runtime warning disabling
by ccn (Vicar) on Jul 26, 2004 at 20:46 UTC | |
by kryten (Scribe) on Jul 26, 2004 at 21:34 UTC | |
Re: Nested runtime warning disabling
by gaal (Parson) on Jul 26, 2004 at 20:42 UTC | |
by kryten (Scribe) on Jul 28, 2004 at 10:02 UTC |
Back to
Seekers of Perl Wisdom