Sleep & print(f) problem

F

Frank

Hi,

I got the following script:

#!/usr/bin/perl

use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep );
use POSIX;

sub lcd_write {
local $fh = shift;
$row1 = $_[1];
$row2 = $_[2];

printf($fh "%1d%1d%-8s\n",0,0,substr($row1,0,8));
printf($fh "%1d%1d%-8s\n",1,0,substr($row2,0,8));
print "write write";

}

open(FILE,"> ./fifo") || die "DOH!! $!";

while() {
lcd_write(\*FILE,"See time",POSIX::strftime("%H:%M:%S",gmtime));

#sleep 1;
}

close(FILE);



this works fine and throws as fast as it can the time to the FIFO. But
when I activate the sleep routine, it never goes into lcd_write. (But it
IS sleeping 1 sec at the time)

I can't figure out why sleep would prevent the prints. (If I put an
other sleep in the subroutine, I can see it doing it's sleep with strace)

Can anyone figure out why the prints aren't working when using a sleep?


Regards,


Frank
 
X

xhoster

Frank said:
this works fine and throws as fast as it can the time to the FIFO. But
when I activate the sleep routine, it never goes into lcd_write. (But it
IS sleeping 1 sec at the time)

I can't figure out why sleep would prevent the prints. (If I put an
other sleep in the subroutine, I can see it doing it's sleep with strace)

Can anyone figure out why the prints aren't working when using a sleep?

Buffering. Turn on autoflush on your fifo handle

Xho
 
T

Tad McClellan

Jim Gibson said:
You can also set the output to be unbuffered by setting ^^^^^^^^^^
the $| variable to non-zero, which will turn off buffering for the ^^^^^^^^^^^^^^^^^^
currently selected output file handle.


Setting $| does NOT make output unbuffered.

Output is still buffered, but with $| true the buffer is flushed
a lot more often.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top