XP is just a number | |
PerlMonks |
Re: no module warnings in client codeby kcott (Archbishop) |
on Aug 27, 2013 at 14:55 UTC ( [id://1051148]=note: print w/replies, xml ) | Need Help?? |
G'day citromatik, In the first instance, you'd probably want to consider why you don't want to see the warnings. Can you rewrite your code so that you don't get warnings in the first place? I'd also question why you want to prevent all warnings (i.e. with no warnings;) rather than just a specific warning (e.g. no warnings 'once';). If you think that the warnings that are emitted are in some way wrong, can you raise a bug report? Can you tell us what actual module you're dealing with? — perhaps we can suggest a fix for your code or some other workaround. Given this module:
There's clearly a bug (albeit highly contrived) which should be fixed. Using it normally:
Looking at the documentation for the warnings pragma, you'll see: "The warnings pragma is a replacement for the command line flag -w, but the pragma is limited to the enclosing block, ..." [my strong emphasis] This is why your posted "something like this" suggestion doesn't work:
However, as an interim measure, you could do something like this:
Notice how I turned off one specific warning to redefine the subroutine; that particular warning is switched back on inside the subroutine (obviously unnecessary for this simple example: I'm making a point about affecting the smallest possible scope when doing this). Also, inside the subroutine, only one specific type of warning is turned off. Probably the biggest problem with that is you'll always be stuck with your version! When the offending subroutine is fixed, enhanced, extended or otherwise modified, your code will continue to use your redefinition. If you provide more information about your specific issue, perhaps we can suggest a better way to deal with it. -- Ken
In Section
Seekers of Perl Wisdom
|
|