我有一个制表符分隔的文本文件,我在其中使用 while 循环根据某些列值进行一些过滤。我将输出写入一个新文件。现在我想将此输出文件用作另一个 while 循环的输入。这是我到目前为止的代码。一定有问题,因为out2.txt
文件是空的。
my $table1 = $ARGV[0];
open( my $file, $table1 ) || die "$! $table1"; #inputfile
open( my $filter1, '+>', "out.txt" ) || die "Can't write new file: $!"; #first output
open( my $filter2, '+>', "out2.txt" ) || die "Can't write new file: $!"; #second output
while (<$file>) {
my @line = split /\t/; #split on tabs
if ( $line[12] =~ /one/ ) {
print $filter1 "$_";
}
}
while (<$filter1>) {
my @line = split /\t/; #split on tabs
if ( $line[11] =~ /two/ ) {
print $filter2 "$_";
}
}
输出文件out.txt
包含正确的信息。然而out2.txt
是空的。有人可以帮我解决这个问题吗?