Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: A delay effect...

by Juerd (Abbot)
on Dec 30, 2001 at 20:06 UTC ( [id://135253]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: A delay effect...
in thread A delay effect...

UPDATE: This is my 100th post! :))

Yes, but think about buffering. Perl won't flush it's buffer until it sees a newline.
You have no \n after the <br>, so this is what happens:
  1. perl fills the buffer
  2. perl sleeps for two seconds
  3. perl appends to the buffer, and then flushes it because the end of the script is reached.
Which of course is not what you want.

You could put a \n after the <br>, or turn on the autoflush using $| = 1 (often seen obfuscated as $|++).

print "First<br>\n"; sleep 2 print "Second\n"; ### $| = 1; print "First<br>"; sleep 2; print "Second";


I recommend the newline solution, because HTML doesn't care about the newline being there, and autoflushing decreases performance.

Information about $| and many other special variables can be found in perlvar.

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Replies are listed 'Best First'.
Re: Re: Re: Re: A delay effect...
by kiat (Vicar) on Jan 05, 2002 at 16:58 UTC
    Hi juerd,

    Your solution doesn't seem to produce the desired result. There four statements are printed at the same time after the long pause, not one after another after each pause.

    kiat
      You are suffering from buffering.
      Either add linebreaks or set $| to 1 ($| = 1;)

      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://135253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-19 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found