jip*_*pie 9 linux perl warnings module
我的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 )
}
Run Code Online (Sandbox Code Playgroud)
一切正常,甚至当我从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 : ................
所以这是关于Use of uninitialized value我想要摆脱的两个警告.其他警告是我自己的日志记录.
kmk*_*lan 12
您可以尝试拦截警告:
$SIG{'__WARN__'} = sub { warn $_[0] unless (caller eq "Device::SerialPort"); };
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3286 次 |
| 最近记录: |