in reply to Re: WRITING TO FILES
in thread Writing to files

And also do $|++; at the top too, so that buffering of stdout is disabled.

Why?

Replies are listed 'Best First'.
Re: Re: Re: WRITING TO FILES
by jdporter (Paladin) on Dec 17, 2002 at 21:09 UTC
    Because die() writes its output to STDERR, which is unbuffered. If the script die's with STDOUT buffered (actually, autoflushed) as per normal, then even if you've printed the header, the die message might precede it in the pipe to the server, and that will hose the http message. You must have the http header first, and the way to ensure that is to unbuffer STDOUT. I suppose you could also just write the header to STDERR, but would be, um, less conventional.

    jdporter
    ...porque es dificil estar guapo y blanco.

      Which webserver do you use that sends STDERR to the client?

        I did not say webserver -> client, I said CGI -> webserver. When a (typical) web server spawns the perl process running your CGI script, it collects both STDOUT and STDERR from that process.

        jdporter
        ...porque es dificil estar guapo y blanco.

      What kind of help would writing the header to STDERR be?

      Makeshifts last the longest.