I have a problem. Currently I am trying to compare two text files which has high amount of data. I have developed a perl script to cross check both files. But it takes very long time. The codes are working fine for small number of data. The sample files are attached here.
I want the 1st line of chr.txt file to check all the lines in exon.txt. it should repeat the process until all the lines from chr.txt is checked with lines from exon.txt.
This the code which i developed.
I want the 1st line of chr.txt file to check all the lines in exon.txt. it should repeat the process until all the lines from chr.txt is checked with lines from exon.txt.
This the code which i developed.
Code:
use strict;
use warnings;
my $file1 = "exon.txt";
my $file2 = "chr.txt";
open(FILE1, $file1) || die "couldn't open the file!";
open(FILE2, $file2) || die "couldn't open the file!";
open(OUT,">result.txt");
my @arr1 =<FILE1>;
my @arr2 =<FILE2>;
foreach my $arr1 (@arr1){
chomp $arr1;
my ($eChr,$eStart,$eEnd,$eCat)=split(/\t/,$arr1);
foreach my $arr2 (@arr2) {
my($cChr, $cStart, $cEnd)=split(/\t/, $arr2);
if (($mChr eq $eChr)&&($mStart >= $eStart) && ($mEnd <= $eEnd)) {
print OUT "$mChr\t$mStart\t$mEnd\t$eCat\t$eStart\t$eEnd\n";
}
}
}
close(FILE1);
close(FILE2);
close OUT;
Comment