J
Jie
below I am trying to compare if a list of files have common elements
in certain columns. This code works fine. The problem is that the last
two line I manually writes the array element. Is there a way to put
the "if" into a loop, so that I can just use "$lists[$i]" to loop the
whole thing??
thanks!
Jie
========my current code=========
@lists = ("A", "B", "C");
foreach $list (@lists) {
%{$list} = (); ## create an empty hash of each element
open IN, " < pValue_DATA/$list.txt";
while (<IN>) {
chomp;
$_ =~ /(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$WGAS_HASH{$SNP}\t${$lists[0]}{$SNP}\t${$lists[1]}
{$SNP}\t${$lists[2]}{$SNP}\n";
}
}
in certain columns. This code works fine. The problem is that the last
two line I manually writes the array element. Is there a way to put
the "if" into a loop, so that I can just use "$lists[$i]" to loop the
whole thing??
thanks!
Jie
========my current code=========
@lists = ("A", "B", "C");
foreach $list (@lists) {
%{$list} = (); ## create an empty hash of each element
open IN, " < pValue_DATA/$list.txt";
while (<IN>) {
chomp;
$_ =~ /(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$WGAS_HASH{$SNP}\t${$lists[0]}{$SNP}\t${$lists[1]}
{$SNP}\t${$lists[2]}{$SNP}\n";
}
}