So I see the requirements are becoming more refined.
Ok, now...a re-write of my previous post...
#!/usr/bin/perl
use warnings;
use strict;
# this uses a "trick" to open an in memory file
# like a file on the disk for testing purposes
my $file1 =<<END;
1 19002930 0.74
1 19002931 -0.12
END
my $file2 =<<END;
1 19002930 0.84 0.12 0.94
1 19002931 0 -.20 .12
END
open (my $fh1, '<', \$file1) or die "$!";
open (my $fh2, '<', \$file2) or die "$!";
my %hash;
#generate hash table from file 1
while (my $line=<$fh1>)
{
my ($Col1, $Col2, $Col3) = (split ' ', $line);
$hash{"$Col1 $Col2"} = $Col3;
}
#if col1,2 from file 2 match, then output
#col1,2 and all fields >= the col3 field from file1
while (my $line=<$fh2>)
{
my ($Col1, $Col2, @file2rest) = split ' ', $line;
if (defined $hash{"$Col1 $Col2"})
{
print "$Col1 $Col2 ";
print join" ", grep{ $_>=$hash{"$Col1 $Col2"}}@file2rest;
print "\n";
}
}
__END__
prints:
1 19002930 0.84 0.94
1 19002931 0 .12
|