Hi there:

I am very new in Perl and I am trying to write a script to search for
similar text in two different files, If it founds a match, it should out
put the whole line from the second file in a third file.



Let say that my first file (F1) has a list of some samples like

>Cortezaaerea23489284

>Cortezaterreste0714857



And the second file (F2) has information about all my universe of samples

>Cortezaaerea23489284
QIUEFQIFNIQAONDAIFIQHFAIFAUIFNUAINAHDUFUDHJAHFUAHFUAFYAUFAUHADUHAUFHAUHFUAHUAHFUAUFAUFHAUFHAUFHUAHFUDAHFUAFUAI

>Cortezaterreste0918347
QIUEFQIFNIQAONDAIFIQHFAIFAUIFNUAINAHDUFUDHJAHFUAHFUAFYAUFAUHADUHAUFHAUHFUAHUAHFUAUFAUFHAUFHAUFHUAHFUDAHFUAFUAI

>Cortezaterreste09899897
IADUFIAJIOADFIOAMCIADFAIUFIAUFIOAUFDIOAUFAIUFAIIUFIAUFIDAUFIAIAUFIAUFIAUFIOAUFIOAUDOIFAUIODUAIOFUAIOFUAIUFOIAUFIAOUFDOIAU

>Cortezaaerea234789048
IADUFIAJIOADFIOAMCIADFAIUFIAUFIOAUFDIOAUFAIUFAIIUFIAUFIDAUFIAIAUFIAUFIAUFIOAUFIOAUDOIFAUIODUAIOFUAIOFUAIUFOIAUFIAOUFDOIAU

>Cortezaterreste0714857


IADUFIAJIOADFIOAMCIADFAIUFIAUFIOAUFDIOAUFAIUFAIIUFIAUFIDAUFIAIAUFIAUFIAUFIOAUFIOAUDOIFAUIODUAIOFUAIOFUAIUFOIAUFIAOUFDOIAU



The output for this example should be like this

>Cortezaaerea23489284
QIUEFQIFNIQAONDAIFIQHFAIFAUIFNUAINAHDUFUDHJAHFUAHFUAFYAUFAUHADUHAUFHAUHFUAHUAHFUAUFAUFHAUFHAUFHUAHFUDAHFUAFUAI

>Cortezaterreste0714857


IADUFIAJIOADFIOAMCIADFAIUFIAUFIOAUFDIOAUFAIUFAIIUFIAUFIDAUFIAIAUFIAUFIAUFIOAUFIOAUDOIFAUIODUAIOFUAIOFUAIUFOIAUFIAOUFDOIAU



My script is as follows, it work partially but always just with the last
element in file 1. Could anyone help me to improve it?



open (A,"C:/F1.txt");

print "openA\n";

open (B,"C:/F2.txt");

print "openB\n";

open (OUT,">>C:/R1.txt");

my @arr=<A>;

close (A);

my $Names;

while ($line = <B>){

    print "$Names";@fields = split (/\t/,$line);

    our $Seq = "$fields[0]\t$fields[1]";

    our $Label = "$fields[0]";

    foreach $Names (@arr){

# when I try to print “$Names” here; it print each element of the array.

#but when I try the next comparison

     if ($Names eq $Label){

    print OUT "$Seq";

#it just identify the last element of the array

}

}

}

close (B);

close (OUT);



The scrip run but the output file just contains one “Seq” instead of two. I
try to print on the screen all the steps, and apparently the only problem
is the comparison


if ($Names eq $Label){

    print OUT "$Seq";.



I check other post with similar problem but I just can not understand where
is the error.


Thanks on advances


Yuma More

Reply via email to