linux – 如何抑制从加载的模块的代码中发出的Perl警告?

linux – 如何抑制从加载的模块的代码中发出的Perl警告?,第1张

概述我的Perl程序正在从通过USB连接的串行设备读取数据.伪Perl中的脚本标题: use warnings;use strict;use Device::SerialPort;my $PortObj = tie( *$handle , "Device::SerialPort" , $PortName ) or die "Cannot open serial port: $!\n";whi 我的Perl程序正在从通过USB连接的串行设备读取数据.伪Perl中的脚本标题:
use warnings;use strict;use Device::SerialPort;my $PortObj = tIE( *$handle,"Device::SerialPort",$Portname ) or dIE "Cannot open serial port: $!\n";while ( 1 ) {  my $readLength = read( $handle,my $frameData,$frameLength )}

一切工作正常,即使我从USB拔出设备我可以从这种情况恢复,当设备文件消失并重新出现.我可以捕获从我自己的脚本产生的所有错误,但加载的模块(Device :: SerialPort)也产生警告,我不希望它们出现在我的日志记录中.

我可以在我的代码中添加一些标志,所以我看不到这些特定的警告?对我来说重要的是只有模块的警告被抑制,而不是我自己的脚本中的警告.目前看起来像这样:

[/dev/ttyUSB1]   0x0020 : 00 00 00 00 00 00 00 00 00 AA 93 82 73 68 5E 58 : ............sh^X[/dev/ttyUSB1]   0x0030 : 55 54 52 52 4F 4E 50 51 50 00 00 00 00 00 00 00 : UTRRONPQP.......Use of uninitialized value $count_in in addition (+) at /usr/lib/perl5/Device/SerialPort.pm line 2214.Use of uninitialized value $string_in in concatenation (.) or string at /usr/lib/perl5/Device/SerialPort.pm line 2232.[/dev/ttyUSB1] Restart required![/dev/ttyUSB1] Cannot open serial port: No such file or directory[/dev/ttyUSB1] Cannot open serial port: No such file or directory[/dev/ttyUSB1] Cannot open serial port: No such file or directory[/dev/ttyUSB1]   0x0000 : 41 42 01 40 71 01 1C E4 80 99 80 80 80 80 00 00 : AB.@q...........[/dev/ttyUSB1]   0x0010 : 00 03 00 00 83 00 01 01 00 00 00 00 00 00 00 00 : ................

所以这是关于两个使用未初始化的值警告,我想摆脱.其他警告是我自己的日志记录.

> libdevice-serialport-perl 1.04-2build1
> perl v5.12.4

解决方法 你可以尝试拦截警告:
$SIG{'__WARN__'} = sub { warn $_[0] unless (caller eq "Device::SerialPort"); };
总结

以上是内存溢出为你收集整理的linux – 如何抑制从加载的模块的代码中发出的Perl警告?全部内容,希望文章能够帮你解决linux – 如何抑制从加载的模块的代码中发出的Perl警告?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1049251.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存