Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Problem using sleep

I have encountered a strange problem using the sleep builtin function.

Here is a REALLY simple program that demonstrates the issue

#!/usr/bin/perl

while(1) {
 print "hi\n";
 sleep 1;
}

This program hangs indefinitely. Hi is not printed out. Remove the call to sleep() and the program, as expected, endlessly prints hi. I have tried sleep(1), but to no avail.

I am using perl 5.8.0 on redhat 8.0 - 2.4.18-26.8.0smp.

This makes NO sense.
0
edschmoe
Asked:
edschmoe
1 Solution
 
ozoCommented:
Try setting
$| = 1;
0
 
prady_21Commented:
Just give the sleep before the print "Hi"; statement and it will work fine
:> Hope that helps
0
 
prady_21Commented:
Anyway your program is working perfectly fine with my system too :>
0
 
TintinCommented:
Solution as ozo proposed.

The output is being buffered.

perldoc -q buffer
0
 
edschmoeAuthor Commented:
Thanks, flushing output worked!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now