in reply to Re^2: Perl: How to perfectly match specific data between two files and do comparison?
in thread Perl: How to perfectly match specific data between two files and do comparison?
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}}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl: How to perfectly match specific data between two files and do comparison?
by WWq (Novice) on Jul 24, 2013 at 14:35 UTC | |
by Loops (Curate) on Jul 24, 2013 at 18:00 UTC | |
|
Re^4: Perl: How to perfectly match specific data between two files and do comparison?
by WWq (Novice) on Jul 25, 2013 at 03:04 UTC | |
by Loops (Curate) on Jul 25, 2013 at 03:22 UTC |