perl 无法从输入文件句柄读取输入[已关闭]

0h4hbjxa  于 6个月前  发布在  Perl
关注(0)|答案(1)|浏览(84)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。

这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
26天前关闭
Improve this question
我有一个Perl和处理输入文件的问题。
我正在成功打开文件;但是,当我尝试将文件的内容打印到屏幕时,它不打印任何内容。
如果我在尝试打印到屏幕之前对该文件名执行系统调用cat,则打印到屏幕工作?!

  • 不工作 *
open( my $ifh, "<", "$stream->{ fname }.SortIndex.dat" )
    or die "$product: $stream->{ fname }.SortIndex.dat could not open parm file file.dat: $!";

while ( <$ifh> ) {
    print $_;
}

字符串

  • 工作 *
open( my $ifh, "<", "$stream->{ fname }.SortIndex.dat" )
    or die "$product: $file could not open parm $stream->{ fname }.SortIndex.dat: $!";

system ( "cat $stream->{ fname }.SortIndex.dat" );

while ( <$ifh> ) {
    print $_;
}


这让我很困惑,我试过把句柄扔到一个数组中并打印数组的元素,但没有成功。
文件句柄打开没有错误,它只包含一行,它是一个Unix的文本文件。
有人见过这种行为吗?

  • 我现在也在同一个文件上执行cat:*
system( "cat $stream->{ fname }.SortIndex.dat" );


以前的行为仍然存在。

ozxc1zmp

ozxc1zmp1#

大卫让我走上了正道。
在运行例程打开SortIndex.dat文件进行下一阶段的处理之前,我没有关闭它们。
我只能想象通过system()调用cat会刷新缓冲区并写出文件。
对不起,浪费了你的时间,这是一个漫长的一周.......
感谢大家的投入。

相关问题