我有這段代碼來讀取traceroute的輸出以進行監視。Perl for循環僅在調用特定的子集時迭代一次
下面的這段代碼工作正常。
for ($i = 0; $i < $sizeloc; $i++) {
for ($j = 0; $j < 1; $j++) {
if ($j==0) {
system("tracert " . $locations[$i][$j] . " > d:\\netmon\\"
. $locations[$i] [$j+1]);
}
}
}
只要我叫這個子read_outputfile($ locations [$ i] [$ j + 1]);在循環內發生問題。它只是迭代一個對象,然後我的程序結束。所以第一次調用read_outputfile時,它會運行子代碼。只有它不會返回到循環。它只是完成。
for ($i = 0; $i < $sizeloc; $i++) {
for ($j = 0; $j < 1; $j++) {
if ($j==0) {
system("tracert " . $locations[$i][$j] . " > d:\\netmon\\" .
$locations[$i][$j+1]);
read_outputfile($locations[$i][$j+1]);
}
}
}
sub read_outputfile{
my($location) = @_;
open ($location, "$location");
while ($record = <$location>) {
$i++;
if ($i == 8) {
$out = substr($record , 32);
if($out != "88.15.160.255") {
mail($location);
}
}
}
close($location);
}
任何輸入?
'read_outputfile'的定義是什麼? – bvr 2011-02-28 13:33:53
'$ out!=「88.15.160.255」'可能沒有達到您的預期 - '!='是一個數字比較運算符;使用'ne'進行字符串比較。 – mob 2011-02-28 13:39:58
'嚴格使用;使用警告;'會發現這個錯誤。始終嚴格執行併發出警告。 – friedo 2011-02-28 13:58:38