【发布时间】:2016-04-01 01:00:12
【问题描述】:
这是一个大代码的sn-p,如果没有匹配则打印Use of uninitialized value $match in string eq at <script path> line 7.。
我正在使用if (!defined $match),它不应该抑制这个警告吗?我正在使用 Perl 5.18 版
my $match = '';
my $prematch = '';
my $i = 1;
$obj->{comm}->print( $command ); #$obj->{comm} is Net::Telnet
while ($match eq '' and $i < 3) {
( $prematch, $match ) = $obj->{comm}->waitfor( Match => "/$pattern/");
print "\npattern not found, try again..." if (!defined $match); #line 7
$i++;
}
【问题讨论】:
-
警告是关于
eq,而不是defined,所以问题可能出在while ($match eq '' and $i < 3) {。我猜$obj->{comm}->waitfor正在将$match设置为 undef。
标签: perl