You need to change the regex that pulls the name out of the text, to something like:
/^\s*(\S+(?:.*\(.*\))?).+\s(\S+)\s*$/
Okay, here's a slightly updated version that includes that regex, and a minor cleanup:
use strict;
use warnings;
sub readReport {
my $filename = shift;
my %hash;
open (my $file, '<', $filename) or die $!;
while (<$file>) {
next unless /^--------/ .. eof; # Bypass header
if (my ($name, $score) = /^\s*(\S+(?:.*\(.*\))?).+\s(\S+)\s*$/
+) {
$hash{$name} = $score;
}
}
return \%hash;
}
my $reportA = readReport('filea');
my $reportB = readReport('fileb');
my %reports = ( fail => [], ignored => [], noCheck => [], pass => [] )
+;
for my $name (sort keys $reportA) {
my ($a,$b) = ($reportA->{$name}, $reportB->{$name});
if ($a < 0) {
push $reports{'noCheck'}, "$name, $a $b" if defined $b;
push $reports{'ignored'}, "$name, $a 0" unless defined $b;
} elsif ($a > 50 and $b > 40) {
push $reports{'pass'}, "$name, $a $b";
} else {
push $reports{'fail'}, "$name, $a $b";
}
}
for my $name (keys %reports) {
print "\nReport $name\n----------------------\n" ;
print "$_\n" for @{$reports{$name}};
}
|