Using "Sleep "

G

George Kinley

for(;;)
{
print "a";
sleep (1);
}

The above script does not print any thing on console , till I modify
it like

for(;;)
{
print "a\n";
sleep (1);

}
why?
 
P

Paul Lalli

George Kinley said:
for(;;)
{
print "a";
sleep (1);
}

The above script does not print any thing on console , till I modify
it like

for(;;)
{
print "a\n";
sleep (1);

}
why?

This is known as output buffering. By default, STDOUT is line-buffered,
meaning the printed strings get stored until a newline is reached, at
which point everything is printed. This is controlled by the $|
variable.

Read
perldoc -q buffer
and
perldoc perlvar

to learn more about it.

Paul Lalli
 
E

Eric Bohlman

for(;;)
{
print "a";
sleep (1);
}

The above script does not print any thing on console , till I modify
it like

for(;;)
{
print "a\n";
sleep (1);

}
why?

Output buffering. perldoc -q flush will give you the detailed answer and
the appropriate workaround.
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top