Perl warning statements being printed without 'use warnings' or -w in any files

夙愿已清 提交于 2019-12-02 05:11:46

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, and what can be fine-tuned. 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

Note that longmess is unfortunately no longer so standard and well supported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!