I have some broblem about merging two files. this is my perl code which is not completed.
$filename = "delete.txt";
unless ( -e $filename ) {
print "The file $filename does not seem to exist \n";
exit;
}
print "\nThe file $filename exist and will be uploaded.\n";
unless ( open(FILEA , $filename)) {
print "Can not open $filename \n";
exit;
}
my @readdata = <FILEA>;
close FILEA;
$filenameB = "delete2.txt";
unless ( -e $filenameB ) {
print "The file $filenameB does not seem to exist \n";
exit;
}
print "\nThe file $filenameB exist and will be uploaded.\n";
unless ( open(FILEB , $filenameB)) {
print "Can not open $filenameB \n";
exit;
}
my @readdataB = <FILEB>;
close FILEB;
#---extracting term from the first array
my $linenum = @readdata;
my $currline = 0;
for($currline = 0; $currline < $linenum; $currline++)
{
my @splitdataA = split(" ", $readdata[$currline]);
my $geneA = $splitdataA[2];
push (@exgenesA, $geneA);
}
my $linenumB = @readdataB;
my $currlineB = 0;
for($currlineB = 0; $currlineB < $linenumB; $currlineB++)
{
my @splitdataB = split(" ", $readdataB[$currlineB]);
my $geneB = $splitdataB[1];
push (@exgenesB, $geneB);
}
@union = @isect = ();
%union = %isect = ();
foreach $e(@exgenesB)
{
$union{$e} = 1;
}
foreach $e(@exgenesA)
{
if ($union{$e})
{
$isect{$e} = 1;
}
$union{$e} =1;
}
@union = keys %union;
@isect = keys %isect;
print join (",", sort @isect);
exit;
--------------------
input file (delete.txt)
cd A1 B1 0.1
cd A2 B2 0.3
cd A3 B4 0.2
cd A5 B3 0.2
cd A6 B3 0.2
---------------------------
input file (delete2.txt)
ab B1 A1 0.2
ab B2 A2 0.3
ab B3 A4 0.2
ab B5 A3 0.2
---------------------------
I tried search for pair of matching data
the results should be
Output :
A1 B1 0.1 B1 A1 0.2
A2 B2 0.3 B2 A2 0.3
A3 B3 0.2 B3 A4 0.2
---------------------------
But in my code, i can only get intersec between them that are B1,B2 and B3.
Could you please suggest me about extracting output like as over output.
Thank you so much.