in reply to Imposing no warnings xxx upon callback code?

This maybe a way that can help you remove some warning you dont want.

# remove unwanted warnings $SIG{__WARN__} = sub { my $wn = shift; return if $wn =~ /Use of uninitialized value/i; #Most annoying return if $wn =~ /name "(?:.+?)" used only once/i; #Very annoying warn $wn; };

Good Luck!

Updated: I have updated the code above "$SIG{__DIE__}" to "$SIG{__WARN__}". Sorry for any problems.

Replies are listed 'Best First'.
Re^2: Imposing no warnings xxx upon callback code?
by ikegami (Patriarch) on Dec 22, 2006 at 19:32 UTC

    As I fruitlessly tried to explain to you privately, $SIG{__DIE__} is not appropriate here. $SIG{__WARN__} is required. Maybe if I post a test you can run...

    use strict; use warnings; $SIG{__DIE__} = sub { my $wn = shift; return if $wn =~ /Use of uninitialized value/i; #Most annoying return if $wn =~ /name "(?:.+?)" used only once/i; #Very annoying warn $wn; }; print 123 + undef, "\n"; # We want to hide this warning. print 123 + 'abc', "\n"; # We want to see this warning.

    outputs

    Argument "abc" isn't numeric in addition (+) at 591379.pl line 12. Use of uninitialized value in addition (+) at 591379.pl line 11. 123 123

    If you change $SIG{__DIE__} to $SIG{__WARN__}, you get the desired output.

    Argument "abc" isn't numeric in addition (+) at 591379.pl line 12. 123 123

    Update: Regarding your update, $SIG{} = sub { ... }; is no good either. It's a syntax error.

      ya, I can be wrong!
      $SIG{__WARN__} = sub { my $wn = shift; return if $wn =~ /Use of uninitialized value/i; #Most annoying return if $wn =~ /name "(?:.+?)" used only once/i; #Very annoying warn $wn; };

      Good Luck!