in reply to Imposing no warnings xxx upon callback code?

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.

Replies are listed 'Best First'.
Re^2: Imposing no warnings xxx upon callback code?
by BrowserUk (Patriarch) on Dec 22, 2006 at 16:38 UTC
    No, warnings overrides $^W/-w (regardless of their relative order).

    Of course. I knew there was a good reason for not using warnings :)

    $SIG{__WARN__} achieves my goal. Thankyou.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.