in reply to Read and analyze two file in parallel
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read and analyze two file in parallel
by CountZero (Bishop) on Mar 14, 2012 at 22:45 UTC | |
|
Re^2: Read and analyze two file in parallel
by remluvr (Sexton) on Mar 14, 2012 at 22:06 UTC | |
by aaron_baugher (Curate) on Mar 14, 2012 at 22:21 UTC | |
|
Re^2: Read and analyze two file in parallel
by Anonymous Monk on Mar 15, 2012 at 08:39 UTC | |
by Anonymous Monk on Nov 21, 2012 at 10:58 UTC |