Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here is the sample code:
#!/usr/bin/perl use CGI; $| = 1; print "Content-type: text/html\n\n"; print "Hello"; sleep 10; print "World\n";
I have pasted this code in cgi-bin directory. when i tried to run throuth command prompt it first displays Hello then World with a sleep of 10 sec. In case of browser Hello and World are coming at once without any time delay. can anyone suggest me a method to how to flush the vales to the browse?????

Edited by Chady -- code tags.

Replies are listed 'Best First'.
Re: Query about Perl-CGI
by muba (Priest) on Jul 08, 2004 at 10:37 UTC
    You can't. Most browsers will start rendering when enough information has been received or when the complete page has been downloaded. Just two words is not enough.
    Anyway, you might try flushing. For more information, see the $| section in the perlvar manpage. You might also want to have a look at suffering from buffering, a very interesting and clear article.

    But this might not work as you want it to work. To really give one word first, and then the other, in a web-based environment, I'd suggest you to buy a nice book about Perl and learn about server push and/or client pull.

    Update: Oh and besides, would you be so kind to put your code in <CODE> tags? It makes your post more readable. See Writeup Formatting Tips
    Update: clarified my message a little. Corrected some typo's too.
    "2b"||!"2b";$$_="the question"
Re: Query about Perl-CGI
by jeffa (Bishop) on Jul 08, 2004 at 14:37 UTC