【发布时间】:2015-03-17 03:05:50
【问题描述】:
我正在执行 perforce 命令的行如下:
2806 I deep sd_bordeaux 117:02:40 IDLE none
2807 I deep sd_bordeaux 17:02:40 IDLE none
2808 I deep sd_coddeaux 117:02:40 IDLE all
2809 I rahul sd_coddeaux 117:02:40 IDLE all
我编写了以下代码来运行命令以在 $command 中获取上述列表并将其存储在数组 @lines 中并使用正则表达式来获取指定的条件。但我没有得到想要的结果。
my $command = qx |p4 monitor show -ale|;
my $kill_id;
my @lines = split("\n", $command);
for my $line (@lines){
next if not $line =~ /(\d+)\s+/;
my $id = $1;
if ($line =~ /sd_bordeaux\s+(\d+):\d+:\d+\s+/ and $line =~ /IDLE\s+none$/){
my $hours = $1;
print "$hours";
print "\n";
}
}
我收到一个错误
Use of uninitialized value $hours in string at ./p4.pl
我有兴趣将数字“2806”和“2807”作为 $id,将第一个数字“117”和“17”作为 $hours。
请帮我解决我哪里出错了。谢谢你。
【问题讨论】: