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

From one client's server the following line made for an elegant way to view error messages in the browser when testing a cgi:
close(DATA) or die "Content-type: text/html\n\n\n <P>HRUMPH \n\n <P>$! +";
But I tried to do the same thing on another box and found I had to use the following or I would get an Internal Server Error:
close(DATA) or print "Content-type: text/html\n\n\n <P>HRUMPH \n\n <P> +$!";
This last appears to give me equally verbose error statements. What did I miss? Is this a server-based difference, something the ISP has configured differently? I am guessing the second server does not like the fact that the script died while the first server was not so sensitive?

Thanks, as always, for helping my understanding.

Replies are listed 'Best First'.
(jeffa) Re: die vs. print in CGI
by jeffa (Bishop) on Aug 09, 2001 at 18:31 UTC
    Why not just use CGI::Carp?
    use CGI::Carp 'fatalsToBrowser';
    Now, all errors will be sent to the browser in a platform independent way (provided the platform has the module).

    jeffa

Re: die vs. print in CGI
by RatArsed (Monk) on Aug 09, 2001 at 18:36 UTC
    die() sends it's output to STDERR and quits. Thus nothing does to STDOUT, so the webserver moans.

    You could use Carp qw(fatalsToBrowser)

    --
    RatArsed

Re: die vs. print in CGI
by suaveant (Parson) on Aug 09, 2001 at 18:33 UTC
    This is just a guess, but die makes the program exit with an error (exit(1) I believe)... maybe the web server sees this and considers the script to have died abnormally, so throws an error.

                    - Ant
                    - Some of my best work - Fish Dinner