how to put "if" within a loop

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";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top