in reply to duplicates getting omitted while comparing values inside foreach.

Btree (or lack thereof) isn't the reason for this bug. The bug is in the placement of your print OUT statements. If you clean up the indenting you will notice that lines only print out if

On the rows where it fails to print out, I presume that $variant is defined, but either the left or right flag is something other than 1.

To fix this I recommend that you move the code for calculating the final column into a separate sub that returns either the file name or "-". Then your loop to read in file 2 should (pseudo code) look something like this:

while (my $line = <DATA>) { my @aFields=split(/\s+/,$line); my $kDb= $aFields[0] . '#' . $aFields[1]; my ($variant,$rs) = split('##', $hash1{$kDb}); #code to calculate my $result=calcFinalColumnValue($variant,$rs,\@aFields); #print row print "@aFields $result\n"; }

Also, you might want to consider two changes to make this code more efficient.

Best, beth

Replies are listed 'Best First'.
Re^2: duplicates getting omitted while comparing values inside foreach.
by patric (Acolyte) on Apr 16, 2009 at 09:36 UTC
    i had missed an else statement after if.
    if(defined($variant)){ foreach my $lis(@snplist){ if($queryinfo[2] eq $lis){$flag_left=1;} elsif($queryinfo[3] eq $lis){$flag_right=1;} } if(($flag_left == 1) && ($flag_right == 1)){ print OUT "$_\t$rs\n"; $c++; $flag_left=0;$flag_right=0; } else{ print OUT "$_\t-\n"; } } else{ print OUT "$_\t-\n"; }
    thank u :)
Re^2: duplicates getting omitted while comparing values inside foreach.
by patric (Acolyte) on Apr 16, 2009 at 09:20 UTC
    thank you so much for your valuable suggestions :)