in reply to unimport warnings in another package

Core warnings like this are typically enabled and disabled with a lexical pragma. With the -W command line parameter, you can force warnings to be turned on even where you didn't request it. If you want to disable warnings in "other" code you'd need to hook the global $SIG{__WARN__}. To get around this specific warning ... lesse... you could just empty out the target symbol table. This clobbers everything below your target and allows for some really bad action at a distance.

In short, all the fixes I'm thinking of now are really, really terrible ideas. Please don't do them at work. I'll buy you a mocha.

%{$caller . '::} = (); # clobber our caller. local $SIG{__WARN__} = 'IGNORE'; # temporarily turn off all warnings ( +this is the least bad, imho)

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: unimport warnings in another package
by wazzuteke (Hermit) on Mar 21, 2007 at 13:05 UTC
    Thanks for the reply ... I thought of that, too, but I don't really want to turn off *all* warnings, just the one I want in the scope I want. I suppose I can store off the original handler, go crazy, and re-assign the warn handler to turn warnings back 'on'. I suppose I don't want to go down that road if I don't have to, though.

    Thanks again, though!

    ---------
    perl -le '$.=[qw(104 97 124 124 116 97)];*p=sub{[@{$_[0]},(45)x 2]};*d=sub{[(45)x 2,@{$_[0]}]};print map{chr}@{p(d($.))}'

      If you just localize it with local $SIG{__WARN__} = ... then it'll clean itself up without any work required by you. Further... if you really wanted to you could assign your own sub and filter out just the warnings you want to ignore.

      local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /^Subroutine .+ redefined/; }

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊