J
Jie
as you see below, I am trying to compare if a list of files have
common elements. The following code works. The problem is that for the
last two lines I need to manually write each array element. when the
array is long, it is much awkward.
is there a way to put the "if" inside a loop?
thank you very much!
Jie
==========my code============
@lists = ("A", "B", "C");
foreach $list (@lists) {
%{$list} = ();
open IN, " < $list.txt";
while (<IN>) {
$_ =~ /(rs\d+)\t([^\t]+)/;
${$list}{$1} = $2;
}
close IN;
}
foreach $SNP (%{$lists[0]}) {
if ( exists ${$lists[1]}{$SNP} && exists ${$lists[2]}{$SNP}) {
print OUT "$SNP\t${$lists[0]}{$SNP}\t${$lists[1]}{$SNP}\t${$lists[2]}
{$SNP}\n";
}
}
common elements. The following code works. The problem is that for the
last two lines I need to manually write each array element. when the
array is long, it is much awkward.
is there a way to put the "if" inside a loop?
thank you very much!
Jie
==========my code============
@lists = ("A", "B", "C");
foreach $list (@lists) {
%{$list} = ();
open IN, " < $list.txt";
while (<IN>) {
$_ =~ /(rs\d+)\t([^\t]+)/;
${$list}{$1} = $2;
}
close IN;
}
foreach $SNP (%{$lists[0]}) {
if ( exists ${$lists[1]}{$SNP} && exists ${$lists[2]}{$SNP}) {
print OUT "$SNP\t${$lists[0]}{$SNP}\t${$lists[1]}{$SNP}\t${$lists[2]}
{$SNP}\n";
}
}