0
对Perl来说很新,所以这里可能有一个非常明显的解决方案。我正在通过一个日志文件,并基本上添加到哈希某些东西,但我不断收到:找不到对象方法 - Perl脚本
“找不到对象方法”1339384721“通过包”serv.int“(也许你忘了加载”serv .int“?)在logTest.pl第37行,第9行。” 我初始化这些变量和一切,所以我不明白为什么perl的抱怨......
#!/usr/bin/perl -w
use strict;
use warnings;
my $LOGFILE = '/Users/user/Desktop/logTest';
my $downTime = 0;
my $serviceName = 0;
my %downTimeHash =();
open(LOGFILE, $LOGFILE) or die ("Couldn't open the file.");
foreach my $line (<LOGFILE>) {
chomp($line);
#Checks for 'STATE' lines down
if ($line=~/\s*;DOWN*/ && ($line=~/STATE:\s+([^;]+)/ || $line=~/ALERT:\s+([^;]+)/)) {
#Get time service went down
if ($line=~/\[(\d*)\]*/) {
$downTime = $1;
}
#Get service that went down
if ($line=~/STATE:\s+([^;]+)/ || $line=~/ALERT:\s+([^;]+)/) {
$serviceName = $1;
}
#Add service and down time to hash
%downTimeHash = ($serviceName->$downTime);
}
}
print "%downTimeHash \n";
'1339384721'和'serv.int'是我添加到散列中的两个变量。 – jackie
你的意思是使用'$ serviceName => $ downTime'而不是'$ serviceName - > $ downTime'吗? – mob
显然是这样:)固定它! haha – jackie