我的Perl程序正在通過USB連接的串行設備讀取數據。僞的Perl我的劇本的標題:如何禁止從加載的模塊代碼中發出的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 : [email protected] [/dev/ttyUSB1] 0x0010 : 00 03 00 00 83 00 01 01 00 00 00 00 00 00 00 00 : ................
所以這是關於我想擺脫的兩個Use of uninitialized value
警告。其他警告是我自己的日誌記錄。
- libdevice-的SerialPort-perl的1.04-2build1
- perl的v5.12.4
將這些錯誤報告給作者將是一個好主意。 – ikegami 2012-04-29 09:34:34
按照你的意見。 – jippie 2012-04-29 10:42:26