Perl 语言如何完成两个TXT文件特定列的大小比较?

2025-05-01 14:33:10
推荐回答(5个)
回答1:

my ( @m, $i ) = qw( < < > );
my ( $x, $y, $z ) = map { open my ($f), $m[ $i++ ], $_; $f } 'file1', 'file2', 'file3';
select $z;
(split)[2] > ( split /\s+/, <$y> )[2] ? print : undef while <$x>;

回答2:

open(IN,"file1.txt")||die"......1\n";
open(IM,"file2.txt")||die"......2\n";
open(OUT,">result.txt");
while(chomp($raw1=) and chomp($raw2=))
{
@arr1=split(/\s+/,$raw1);
@arr2=split(/\s+/,$raw2);
if($arr1[2]>$arr2[2])
{
print OUT $raw1,"\n";
}
}
close(IN);
close(IM);
close(OUT);

回答3:

你所说的对应行是指前两列是一样的么?是的话,我就帮你写,用哈希就行了

回答4:

用hash表 很简单的

回答5:

open(FILE1,"FILE1");
open(FILE2,"FILE2");
open(FILE3,">FILE3");
while ($s1=){
$s2=;
($t,$t,$n1)=split(/\s+/,$s1);
($t,$t,$n2)=split(/\s+/,$s2);
print FILE3 $s1 if ($n1 > $n2);
}
close(FILE1);
close(FILE2);
close(FILE3);