如何在 Perl 中刷新文件? [英] How do I flush a file in Perl?

查看:27
本文介绍了如何在 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.

问题是应用程序在脚本完成并关闭文件句柄后开始读取文件.为了避免这种情况,我想在每行追加后刷新.我该怎么做?

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. How can I 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆