Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a question for you guru's out there. The script is supposed to connect to a domain registration server, using an object oriented approach. It currently connects to a test server, and functions just fine. When I try to connect to the real server, I get a wonderful "premature end of script header" error message. I have even put this in an eval statement to try to catch it. I have never seen eval fail to catch something. I have gone through all of the code, and it is indeed the statement within eval. Do any of you guys know if there is a way to die, even if inside of an eval? Joe

Replies are listed 'Best First'.
Re: eval bug?
by btrott (Parson) on Jul 06, 2000 at 01:55 UTC
    That error message--"premature end of script headers"--doesn't necessarily mean that your script died. It could also mean that your script printed something out before it printed out the HTTP headers. Could that be the case? Try running it from the command line, using the "real server", and see what gets printed out, and in what order.

    If you're getting content before headers, that's probably your problem.

Re: eval bug?
by Shendal (Hermit) on Jul 06, 2000 at 01:59 UTC
    Have you tried something like this:
    eval { die "Uh oh, bad stuff happened." }; die $@ if $@; print "Phew. Bad stuff didn't happen.\n";
    Perhaps if you posted the relevant section of your code we can take a closer look.
Re: eval bug?
by ferrency (Deacon) on Jul 06, 2000 at 19:55 UTC
    Although you didn't state it explicitly, it sounds like you're building a cgi-bin script. The "Premature end of script headers" error sounds like your web server complaining, not like perl. The basic problem is, in CGI land, your script must print out valid HTML headers before it prints out Anything Else. Depending on your web server, there are several techniques you can use to try to debug this. Looking in your web server's error log can sometimes give you more information on how your script failed. Running the script from the command line (possibly with a $DEBUG flag, which when active, sets values that would otherwise come from a POST or GET) can help, but unless you have hot pipes on ($|=1), the script output might come out in a different order than it does in CGI-land. Another sometimes useful technique is to put a BEGIN block that prints out a valid header, for debugging:

    BEGIN { print "Content-type: text/plain\n\n"; }

    That will be run before the rest of your code, and will usually ensure the header gets printed out before anything else. Then you can see what the Next Thing is that's printed out; if it's not a valid header, then you know you have a problem.

    And of course, if you give more details on your setup and code snippets, I could make more suggestions.