What is result if File A score is 50 and File B score is 40 ?. Assuming that anything that isn't NC or PASS is FAIL then your code can be reduced to something like this.
#!perl use strict; open (PASS, ">pass.rpt") || die "ERROR: cannot open"; open (FAIL, ">fail.rpt") || die "ERROR: cannot open"; open (NC, ">noCheck.rpt") || die "ERROR: cannot open"; # for test my @PASS=(); my @FAIL=(); my @NC=(); my ($ncc,$pc,$fc); # test data if required my @arr1=();# = ('A;-50','B;51','C;51','D;55'); my @arr2=();# = ('A;51' ,'B;39','C;41','F;57'); file_ext('fileA.txt',\@arr1); file_ext('fileB.txt',\@arr2); check(); print "\nTotal PASS match: $pc\n\n"; print "$_\n" for @PASS; print "\nTotal FAIL match: $fc\n\n"; print "$_\n" for @FAIL; print "\nTotal NC match: $ncc\n\n"; print "$_\n" for @NC; sub file_ext { my ($file,$ar) = @_; open (FILE,'<',$file) or die "Could not open $file"; while (<FILE>){ chomp; # name = first field, score = last field my @f = split /\s+/; #print "$f[0] $f[-1]\n"; push @$ar,"$f[0];$f[-1]"; } } sub check { foreach my $data1 (@arr1) { my ($ep1,$s1) = split ';',$data1; foreach my $data2 (@arr2) { my ($ep2,$s2) = split ';',$data2; next if ($ep1 ne $ep2); # negatives in fileA score if ($s1 =~ /-/){ $ncc++; my $line = sprintf "%-20s %4d %4d",$ep1,$s1,$s2; print NC $line."\n"; push @NC,$line; } # pass elsif (($s1 > 50) && ($s2 >40)){ $pc++; my $line = sprintf "%-20s %4d %4d",$ep1,$s1,$s2; print PASS $line."\n"; push @PASS,$line; } #fail else { $fc++; my $line = sprintf "%-20s %4d %4d",$ep1,$s1,$s2; print FAIL $line."\n"; push @FAIL,$line; } } } } =head1 fileA.txt Jane_let [0] (sa) 58.78 r 66.15 0.00 -33 Alfert_pipe (sa) 74.72 r 92.72 0.00 82 Olive_pipe[8] (sa) 64.28 f 25.40 0.00 58 mass/excel/i60 86.21 r 59.90 0.00 68 Anne_let (sa) 51.98 f 12.69 0.00 -39 yuki/099/pipe 76.52 r 94.32 0.00 -82 frey/let/sa/y589 47.79 f 99.00 0.00 78 alan/excel/sa/y589 97.00 f 96.00 0.00 -70 =head1 fileB.txt Ash_let[9] (sa) 58.78 r 66.15 0.00 33 Alfert_pipe (sa) 74.72 r 92.72 0.00 57 Olive_pipe[8] (sa) 64.28 f 25.40 0.00 20 mass/excel/i60 86.21 r 59.90 0.00 16 Sam_let (sa) 51.98 f 12.69 0.00 -39 yuki/099/pipe 76.52 r 94.32 0.00 82 frey/let/sa/y589 47.79 f 99.00 0.00 30 alan/excel/sa/y589 67.00 f 96.00 0.00 -90 =cut
If the run time is too slow then consider a hash based solution rather than using arrays.
poj

In reply to Re: Perl: How to perfectly match specific data between two files and do comparison? by poj
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.