Answer the question
In order to leave comments, you need to log in
Non-blocking write to file in Perl?
There is perl code running on Windows that writes data to a file.
use warnings;
use feature 'say';
open(FH, '>', 'file.txt');
$i = 10;
while ($i > 0) {
say FH $i;
say $i;
sleep 1;
$i--;
}
close(FH)
open
with sysopen
with adding an attribute O_NONBLOCK
does not work.use Fcntl qw(O_WRONLY O_CREAT O_APPEND O_NONBLOCK);
sysopen(FH, 'file.txt', O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK);
Your vendor has not defined Fcntl macro O_NONBLOCK
sysopen
without O_NONBLOCK
does nothing. Answer the question
In order to leave comments, you need to log in
Wrote a program that reads this file. She reads this file without problems.
use 5.12.0;use warnings;
use Fcntl qw(:flock);
open(FH, '<', 'file.txt') or die;
flock(FH, LOCK_EX|LOCK_NB) or die "Cannot lock - $! $^E\n";
while (<FH>) {
print
}
FH->autoflush(1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question