Pretty new to Perl so there may be a very obvious solution here. I’m going through a logfile and basically adding certain things into a hash but I keep getting a:
“Can’t locate object method “1339384721” via package “serv.int” (perhaps you forgot to load “serv.int”?) at logTest.pl line 37, line 9.”
I’ve initialized these variables and everything so I don’t see why perl is complaining…
#!/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";
I should have used
=>rather than->.