I am trying to add values to arrays in a hash.
foreach my $f (@files) {
my $file = "$logDir/$f";
open my $info, $file or die "Could not open $file: $!";
while (my $line = <$info>) {
chomp $line;
if ($line =~ /CONN.*\[ID=(.*)\].*ID is(.*)/) {
$b = $1;
$a = $2;
$a =~ s/^\s+//;
$bHash{$b} = $a if (exists $aHash{$a});
}
elsif ($line =~ /succ.*\[ID=(.*)\].*/) {
$b = $1;
push(@{ $bHash{$b} }, "bSUCC") if (exists $bHash{$b});
}
elsif ($line =~ /fail.*\[ID=(.*)\].*/) {
$b = $1;
push(@{ $bHash{$b} }, "bFAIL") if (exists $bHash{$b});
}
}
close $info;
}
I am linking two log files together based on a's transaction id and b's transaction id, which are both found on a single log line in b's log.
The first if statement checks for that, and populates %bHash with b->ID = a->Id.
Then I am looking for either success or fail of b's transaction. If I see a success line I take the transaction ID, and if that ID exists in %bHash then I want to push the "bSucc" message to the end of the array, i.e. %bHash would have bSid -> aSid, bSucc.
I get the following error/warning message:
Can't use string ("7747395") as an ARRAY ref while "strict refs" in use at ./report.pl line 54, <$info> line 833.
Is there a way to do this?
I also want to continue to add information to the array if possible as I scan the log for more data. I want to use the transaction ID as the key and just add info as necessary. Is this possible? Is there a better way to accomplish the task?
Edit: What I am trying to accomplish is to compile information about a transaction across 3 different log files. I want to find the following for each transaction: Success of Fail, If failed where did it fail, in log a, b, or c?
One transaction is handled by 3 different apps, hence 3 different logs. Unfortunately the trans id is different in app a vs apps b and c. So i built a hash with all the trans ids in log a, and then there is a log line in log b that allows you to see the link between the trans id used for log a and trans id used for log b. That is why I am matching trans id from b against the hash from log a. Ultimately I want the info for each transId as mentioned above, sucs/fail, etc.
$bHash{$b}to the A Transaction ID, and then trying to push onto it as if it is an array reference. Please show theformat of your data files and describe exactly what it is that you need to do. It really looks like this belongs in a database.$aand$bas general-purpose variables, first of all because they aren't at all descriptive (the same reason you shouldn't call a hash%bHash) and secondly because they are used internally by Perl and you may get a clash of access.