in reply to Re: Print Header in Perl v5.8.7
in thread Print Header in Perl v5.8.7

Here's the code:

#!/usr/bin/perl -w use CGI qw(:all); use strict; open(TESTFILE, ">thetestfile") || die "Cannot open $!"; close(TESTFILE); print header; print "DONE";
The result is the following on the browser:

CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers.

What does this mean? What's going wrong?

Thanks in advance.

Gorby

Replies are listed 'Best First'.
Re^3: Print Header in Perl v5.8.7
by chromatic (Archbishop) on Aug 19, 2005 at 17:16 UTC

    Your program couldn't open the file and died before it printed the header. I'm sure if you look in the error log you'll see the message.

    If you print the header before you try to open the file, you won't see the 500 error.

      It didn't die. When I run the .cgi program from the command prompt, it works just fine. It outputs the html headers before printing DONE. Somehow, the html header isn't being sent to the browser.

      Would you have more suggestions for me?

      Thanks.

      Gorby

        You are using a relative path. The current directory is not what you think it is. Your script dies before printing valid HTTP headers. Always print out valid headers first. Or use CGI::Carp with the fatalsToBrowser option.

        It didn't die.

        How do you know that? Did you read the error message in the error log or are you just guessing? Do you know why it might die when run from the web server but not from the command line? I do. Corion does.

        You don't have to believe me and you certainly don't have to take my advice, but if you don't really want help and aren't willing to take advice from people who've solved this problem at least a few times before, please make a note to that effect in your original post so we don't have to waste our time giving answers that you will ignore.