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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.