Re: $|=1;
by Ovid (Cardinal) on Nov 05, 2002 at 18:16 UTC
|
| [reply] |
(jeffa) Re: $|=1;
by jeffa (Bishop) on Nov 05, 2002 at 18:03 UTC
|
$| If set to nonzero, forces a flush right away and
after every write or print on the currently
selected output channel. Default is 0 (regardless
of whether the channel is really buffered by the
system or not; `$|' tells you only whether you've
asked Perl explicitly to flush after each write).
STDOUT will typically be line buffered if output
is to the terminal and block buffered otherwise.
Setting this variable is useful primarily when you
are outputting to a pipe or socket, such as when
you are running a Perl program under rsh and want
to see the output as it's happening. This has no
effect on input buffering. See the getc entry in
the perlfunc manpage for that. (Mnemonic: when
you want your pipes to be piping hot.)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] |
Re: $|=1;
by DigitalKitty (Parson) on Nov 05, 2002 at 18:03 UTC
|
Hi Dean.
Setting $| to 1 will turn off line buffering. Normally, a socket will wait until the buffer has filled before sending the data. This can be a source of trouble if the receiving socket is waiting and the data hasn't been sent yet. The $| = 1 simply eliminates the wait period before it sends.
Hope this helps,
-Katie.
| [reply] |
Re: $|=1;
by VSarkiss (Monsignor) on Nov 05, 2002 at 18:04 UTC
|
It unbuffers the current output stream, so anything you write "appears as soon as possible". Look in perlvar. Also check out the I/O section in the Tutorials here.
| [reply] |
Re: $|=1;
by rochlin (Acolyte) on Nov 05, 2002 at 21:19 UTC
|
Another side note on the above answers:
Why is $| used in the script you're looking at? It's a good idea to use it in any CGI script that is outputing a webpage. If the output buffered (no $|=1) then the delay can cause errors in the generated HTML or might just cause a timeout. It's always a good idea to prevent buffering in a CGI script that generates a webpage.
For a nice place to live in Portland, OR | [reply] |
|
$|=1; is currently in a script for a guestbook-- which obviously generates a webpage, so that makes sense. Thanks for explaining that. I'm having problems with another script-- for a survey (poll)-- that also generates a webpage. (My original question above has a link to it if you'd like to take a look) The problem is that a link in that webpage for "continue" doesn't contain the value that it's supposed to, and is instead just empty quotes (""). Maybe if I add this "unbuffering", then the link will print correctly. Sounds like it's worth a try. Thanks everybody!
| [reply] |
Re: $|=1;
by Molt (Chaplain) on Nov 06, 2002 at 12:18 UTC
|
If you're looking for, or at, guestbook scripts it may be worth you peering at nms which is a well-coded set of drop-in-replacements for the less-than-secure Matt's Script Archive scripts, as started and led by davorg.
If nothing else the fact that they're commented may help you with things such as this. I would look long and hard at these before deciding I could do better myself though, they are very nice.
| [reply] |
|
Thanks, Molt. I'll look at those. Actually, what I'm using now are scripts from BigNoseBird.com. The guestbook that I have set up appears to be working fine. The problem I'm tring to solve is with a survey which won't print the url for "continue", as described in the other node which I link to in my first question above.
| [reply] |
Re: $|=1;
by Anonymous Monk on Apr 23, 2003 at 17:42 UTC
|
is this anything similar to the ReadKey (0) function??? | [reply] |