I have a lot of old Perl code that gets called frequently, I have been writing a new module and all of a sudden I\'m getting a lot of warnings in my error_log for Apache, they a
I take it that the code gets called by running certain top-level Perl script(s).
Then use the __WARN__
hook in those script(s) to stop printing of warnings
BEGIN { $SIG{__WARN__} = sub {} };
Place this BEGIN
block before the use
statements so to affect modules as well.
An empty subroutine is the way to mute warnings since __WARN__
doesn't support 'IGNORE'
.
See warn and %SIG in perlvar. See this post and this post for comments and some examples.
To investigate further and track the warnings you can use Carp
BEGIN {
$SIG{__WARN__} = \&Carp::cluck; # or Carp::confess; to also die
}
which will make it print full stack traces. This can be fine-tuned as you please since we can write our own sub to be called. Or use Carp::Always.
See this post for some more drastic measures (like overriding CORE::GLOBAL::warn)
Once you find a more precise level at which to suppress warnings then local $SIG{__WARN__}
is the way to go, if possible. This is used in a post linked above, and here is another example. It is of course far better to suppress warnings only where needed instead of everywhere.
More detail
Getting stack traces in Perl?
How can I get a call stack listing in Perl?
Note that longmess
is unfortunately no longer so standard and well supported.