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

Re: cgi buffer flush

by io (Scribe)
on Mar 09, 2002 at 11:10 UTC ( #150540=note: print w/replies, xml ) Need Help??

in reply to cgi buffer flush

note the "\r\n\r\n" can be safely written as "\n\n" as perl will convert them when you are on windows. Thus making your code more portable. to flush to buffer, just put $|++ in the head of your script. Offcourse, if you really want the text to appear after 10 seconds i'd use javascript.

Replies are listed 'Best First'.
Re: Re: cgi buffer flush
by fuzzyping (Chaplain) on Mar 09, 2002 at 12:06 UTC
    Isn't "$|++" the same as "$|=1"?

      Isn't "$|++" the same as "$|=1"?

      A lot of people seem to think it is, but it's not.

      • $|++ adds one to the current value of $|.
      • $| = 1 sets the value of $| equal to one.
      If for some reason $| = -1, doing a $|++ will make $| = 0, and usually that is not what $|++ is meant to do.

      $| = 1 is much safer and more straight forward (less ambiguous?).

      Update: Whoops. I was way wrong. A thousand lashes to me for misleading my fellows due to my neglectful ignorance. Thanks to dvergin for the correction and for setting me straight..



      -- Yeah, I'm a Delt.

              If for some reason $| = -1,...

        No. Please don't make assertions like that when you haven't tested them.

        $| is magic. It always equals either zero or one. Nothing else. Behold:

        print "$|\n"; # 0 $| = -1; print "$|\n"; # 1 $|++; print "$|\n"; # 1 $|++; print "$|\n"; # 1 $|--; print "$|\n"; # 0 $|--; print "$|\n"; # 1 $|--; print "$|\n"; # 0
        As you can see, $|++ always sets $| to one (no matter what it was) and $|-- always toggles it.

        I agree that $| = 1; is more clear to newer programmers. But rationalle for that usage has to do with the learning curve and not with the behavior of $|.

        "Perl is a mess and that's good because the
        problem space is also a mess.
        " - Larry Wall

        Makes perfect sense, but under what circumstances would $|=-1, unless those where you specifically defined it as such? I can see where it would be a much better idea to use $|=1 so you don't mistakenly define $| to 2 (or higher).

        OTOH, why haven't more folks discussed the use of the FileHandle or IO modules that support the autoflush method? Wouldn't that negate this argument altogether?

Re: Re: cgi buffer flush
by zengargoyle (Deacon) on Mar 16, 2002 at 06:41 UTC
    "\r\n" is correct in this case. I'm pretty sure it's in the HTTP specs as the official line terminator. I think servers might take "\n", but they don't have to. Telnet is the same way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-10-17 00:13 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (70 votes). Check out past polls.