如何在Perl中刷新文件? [英] How do I flush a file in Perl?
本文介绍了如何在Perl中刷新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Perl脚本,该脚本每3秒向现有文件追加一条新行.另外,还有一个C ++应用程序可以读取该文件.
I have Perl script which appends a new line to the existing file every 3 seconds. Also, there is a C++ application which reads from that file.
问题在于脚本完成并关闭文件句柄后,应用程序开始读取文件.为了避免这种情况,我想在每行追加后刷新,但是我是Perl的新手,不知道该怎么做.
The problem is that the application begins to read the file after the script is done and file handle is closed. To avoid this I want to flush after each line append, but I'm new to Perl and don't know how to do that.
推荐答案
尝试:
use IO::Handle;
$fh->autoflush;
这实际上是作为自动冲洗的一种方式发布在早期问题中我的,询问了实现这一目标的普遍接受的坏方法:-)
This was actually posted as a way of auto-flushing in an early question of mine, which asked about the universally accepted bad way of achieving this :-)
这篇关于如何在Perl中刷新文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文