Perl,如何避免来自非直接包含的模块的诊断消息?
我收到此警告(在“使用诊断;”之后);
在解码 /usr/lib/perl5/HTML/PullParser.pm 第 81 行的实体时,解析未解码的 UTF-8 会产生垃圾。
我的程序是这样的:
...
use diagnostics;
use WWW::Mechanize;
use WWW::Mechanize::Gzip;
...
$m = WWW::Mechanize::GZip->new(
agent => $self->{_agent},
timeout => $self->{_timeout},
);
if (!$m->get($url)) {
die("Impossibile scaricare l'url [$url]");
}
if (!$m->form_number(1)) {
die("Impossibile trovare il form 1");
}
<WARNING IS EMITTED HERE>
...
如何我摆脱它?或者我可以安全地忽略它吗?
更新: 我只是注意到使用 WWW::Mechanize->new() 代替 WWW::Mechanize::GZip->new() 确实可以默默地工作......所以问题来自 GZip 模块......?
I'm getting this warning (after "use diagnostics;");
Parsing of undecoded UTF-8 will give garbage when decoding entities at /usr/lib/perl5/HTML/PullParser.pm line 81.
My program is like this:
...
use diagnostics;
use WWW::Mechanize;
use WWW::Mechanize::Gzip;
...
$m = WWW::Mechanize::GZip->new(
agent => $self->{_agent},
timeout => $self->{_timeout},
);
if (!$m->get($url)) {
die("Impossibile scaricare l'url [$url]");
}
if (!$m->form_number(1)) {
die("Impossibile trovare il form 1");
}
<WARNING IS EMITTED HERE>
...
How to I get rid of it? Or may I safely ignore it?
UPDATE:
I just dotice that using WWW::Mechanize->new() insted of WWW::Mechanize::GZip->new() does work silently... So the problem comes from the GZip module...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你问的问题确实是错误的。 您不想抑制这些警告,而是想阻止它们。
这听起来像是 WWW::Mechanize::Gzip 有问题。无论如何,你并不真正需要它,LWP 内置了 gzip 支持。请参阅 此线程(WWW::Mechanize 是 LWP::UserAgent 的子类),了解如何以更合理的方式实现类似的结果。
First of all, the question you're asking really is the wrong one. You don't want to suppress those warnings, you want to prevent them.
This sounds like WWW::Mechanize::Gzip is buggy. You don't really need it anyway, LWP has gzip support built in. See this thread (WWW::Mechanize is a subclass of LWP::UserAgent) for an explanation on how to achieve similar results in a more sane way.