While 循环不读取从 Perl 代码生成的文件

While loop does not read a file generated from code on Perl

我试图用我在 Perl 中的代码即时生成输出文件:

#!/usr/bin/perl 
use strict;
use Data::Dumper;
use warnings;  
use Bio::Seq;
use Bio::SeqIO; 
use Bio::DB::Fasta;
open my $OUT, "> ./temporal.gff";
           my $seq = $db->get_Seq_by_id($key);
            my $length  = $seq->length;
            my $all = $coord{$key};
            foreach my $keys (@$all[0]){
                    @sorted = sort { $a->[0] <=> $b->[0] } @$all;
                    $num = scalar @sorted;
                    my @new = &infer_gaps(\@sorted, $num, $length);
                    foreach my $ln (@new){
                            my @tmp = split /\s{2, }|\t/, $ln;
                            print $OUT "$key\tFillSequencer\tinference\t$tmp[0]\t$tmp[1]\t\.\t$tmp[2]\t\.\t$specie $key:$tmp[0]\-$tmp[1]\n";
                    }
                    #print Dumper \@new;    
            }
        }

但是,当我想使用这个生成的文件时,作为 while 循环的通常方式,它不会读取这个文件:

open my $ABC, "<./temporal.gff" or die $!;
    my $mRNA_seq;
    while (my $l = <$ABC>){
            chomp $l;
            my @arr = split /\t|\s+/, $l;
            #my $coor = $arr[0] . " " . $arr[3] . " " . $arr[4];
            $frame = $arr[6];
            my $final_seq = $db->seq( $arr[0], $arr[3], $arr[4] );
            my $output_nucleotide = Bio::Seq->new(
                    -seq => $final_seq,
                    -id  => $mRNA_name,
                    -display_id => $mRNA_name,
                    -alphabet => 'dna',
            );
            if ($frame eq '-') {
                    $output_nucleotide = $output_nucleotide->revcom();
            }
            $outfile_coor->write_seq($output_nucleotide);
    }

    close $ABC;

你有什么想法吗?当我 运行 我的代码带有 -d 标志时,它允许我确认代码跳过了最后一个 while 循环......我不知道 FILE HANDLE 变量的定义是否有问题或任何其他问题不会产生警告。提前致谢!

我认为您需要在开始阅读之前关闭该文件。

或者您可以刷新输出,以确保文件在您开始读取之前已完全写入。

sub flush {
   my $h = select($_[0]); my $af=$|; $|=1; $|=$af; select($h);
}

# Flush immediately without turning auto-flush on:
flush($OUT);

有关如何使用 flush 的示例,请参阅此答案:

http://www.perlmonks.org/bare/?node_id=489962