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
- ! defined($variant)
- defined($variant) && ($flag_left==1) && ($flag_right==1)
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.
- use while (<$fh2>) rather than foreach. I believe (someone correct me if I'm wrong), that foreach will cause the entire file to be slurped into an array before the loop starts. This could be a problem in a very large file and defeats the purpose of using a tied hash.
- for the values of %hash1 use an array reference [$variant, $rs] rather than the string "foo##baz". This will eliminate the need to concatenate hash values when reading in file1 and the need to parse them when reading in file2.
Best, beth
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.