Okay, here's a slightly updated version that includes that regex, and a minor cleanup:/^\s*(\S+(?:.*\(.*\))?).+\s(\S+)\s*$/
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}}; }
In reply to Re^3: Perl: How to perfectly match specific data between two files and do comparison?
by Loops
in thread Perl: How to perfectly match specific data between two files and do comparison?
by WWq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |