in reply to Perl: How to perfectly match specific data between two files and do comparison?
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.
poj
If the run time is too slow then consider a hash based solution rather than using arrays.#!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
poj
|
---|
In Section
Seekers of Perl Wisdom