문제

I was working on a script when I suddenly realized I couldn't write to a file.

I've been able to get it down to this bit of code:

use strict;
use warnings;

open(my $out, '>>', 'log.txt') or die "$!";
print $out "test";

while(1){
    sleep 1;
}

I tried taking off buffering by setting $| = 1.

I'm working on a program that runs and does something every 10 minutes, so I am using sleep to wait the 10 minutes.

도움이 되었습니까?

해결책

Unless you set $| to 1 while $out was selected, you didn't do anything.

If your perl is non-ancient, write

$out->autoflush(1);

If your perl is ancient, write

my $prev = select($out);
$| = 1;
select($prev);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top