in reply to Writing to files

Well, since this is a CGI, it is critical that the script print the HTTP headers before any other possible output.
So you should move the print header; line to somewhere near the top. And also do $|++; at the top too, so that buffering of stdout is disabled.

Now, as for your specific bug, you'll probably find that it is indeed the open() which is failing, and thus calling die(). Why is the open() failing? Most likely because the script does not have permission to open the /data.txt file, when run by the server. You will probably need to make adjustments with server/script permissions. Also, you'd do well to add the $! variable to the die() message, since that will contain info on the specific cause of failure.

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

Replies are listed 'Best First'.
Re: Re: WRITING TO FILES
by chromatic (Archbishop) on Dec 17, 2002 at 20:59 UTC
    And also do $|++; at the top too, so that buffering of stdout is disabled.

    Why?

      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?

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

        Makeshifts last the longest.