Assuming the data is in the same order, it should be as easy as something like this (untested):
use strict; use warnings; use autodie; open my $IF1, '<', 'File.in1'; open my $IF2, '<', 'File.in2'; open my $OF, '>', 'File.out'; while (1) { my @Rec1 = split /\s+/, <$IF1>; my @Rec2 = split /\s+/, <$IF2>; $Rec1[-1] += $Rec2[-1]; print $OF join("\t", @Rec1), "\n"; last if eof($IF1) and eof($IF2); }
Of course, you'll have to add checking to verify that the records are compatible. If you sort the files beforehand, then in the event of a mismatch, you should be able to simply re-read the file containing the "smaller" (in value) string.
Update: As CountZero mentions, stopping the loop might be a good idea. So I added the last statement.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Read and analyze two file in parallel
by roboticus
in thread Read and analyze two file in parallel
by remluvr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |