in reply to Using perl hash for comparing columns of 2 files
Your script has a few problems:
You don't store Col2 anywhere in your hash. So you obviously can't compare it with Col3 of the other file. Also you use a hash but then the only thing you do with it is looping through its values!? A hash is for looking up values instantly. If all you do is looping, then an array will be better suited
So (for the hash of file1) you need a hash with Col2 as key and the two comparision values (Col5, Col6) as values. You could use a Hash of Arrays for this:
push @{$hash{$line1}}, $line[2],$line[3];
Now, instead of the foreach loop you just need to check if there is the right value in the hash:
if (exists $hash{$cols[2]}) { if ($p1>= $hash{$cols[2]}[0] and $o2<= $hash{$cols[2]}[1]) { ...
|
|---|