Output:#!/usr/bin/perl 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 @scores = ($reportA->{$name}, $reportB->{$name}); my $rpt = "fail"; if ($scores[0] < 0) { $rpt = defined $scores[1] ? 'noCheck' : 'ignored'; $scores[1] //= 0; } elsif ($scores[0] > 50 and $scores[1] > 40) { $rpt = 'pass'; } push $reports{$rpt}, "$name, @scores"; } for my $name (keys %reports) { print "\nReport $name\n----------------------\n" ; print "$_\n" for @{$reports{$name}}; }
Report pass ---------------------- Alfert_pipe, 82 57 Report noCheck ---------------------- alan/excel/sa/y589, -70 -90 yuki/099/pipe, -82 82 Report fail ---------------------- Olive_pipe, 58 20 frey/let/sa/y589, 78 30 mass/excel/i60, 68 16 Report ignored ---------------------- Anne_let, -39 0 Jane_let, -33 0
In reply to Re: 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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |