Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flush a file in Perl?

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?

like image 411
Mihran Hovsepyan Avatar asked Sep 09 '25 15:09

Mihran Hovsepyan


1 Answers

Try:

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 :-)

like image 136
3 revs, 2 users 84% Avatar answered Sep 12 '25 21:09

3 revs, 2 users 84%