#!/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}}; }
Output:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.