I can suppress all warnings using $^W
No, warnings overrides $^W/-w (regardless of their relative order).
use warnings; BEGIN { $^W = 0; } my $s = '' . undef(); # Use of uninitialized value
Not just use warnings;. no warnings; overrides $^W/-w too (regardless of their relative order).
no warnings; BEGIN { $^W = 1; } my $s = '' . undef(); # [No warnings]
In the context of your problem, $^W won't work if the sub was compiled with use warnings; in effect.
use strict; use warnings; sub test (&) { my $code = shift; local $^W = 0; $code->( undef ); } test { print "@_"; # Use of uninitialized value };
That leaves you with $SIG{__WARN__}. You can catch the warnings and filter out the ones you don't want.
Update: Adjusted formatting for coherence. Added example to show that no warnings; overrides $^W too.
In reply to Re: Imposing no warnings xxx upon callback code?
by ikegami
in thread Imposing no warnings xxx upon callback code?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |