in reply to Re: perl,cgi and apache woes
in thread perl,cgi and apache woes

Building on chromatic's advice, I wanted to add that you will speed your development time if you add something extra to your CGI script. At the top of the script:

use CGI::Carp qw( fatalsToBrowser );

This enables you to redirect those error messages from your server's logfile directly to the browser window. This may or may not be appropriate once the application is put into final end-user-use. But during development it definately saves you from running to the server error log every 30 seconds.

Once you've placed that line in your file, you need to also supply a error redirect subroutine. Here's the one I use (thanks to CGI Programming with Perl, from O'Rielly).

BEGIN { sub carp_error { my $error_message = shift; my $cq = new CGI; print $cq->start_html( "Error" ), $cq->h1("Error"), $cq->p( "Sorry, the following error has occurred: " ), $cq->p( $cq->i( $error_message ) ), $cq->end_html; } CGI::Carp::set_message( \&carp_error ); }

That ought to do it.

You may already know this but the CGI.pm module allows you to run your CGI scripts from the command line, so that the output goes straight to <STDOUT> (your terminal screen). If you need to set certain key=>value parameters to test how the script reacts, you do that directly from the command line too. See the CGI.pm POD for more info. I find that also to be an invaluable debugging tool.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: Re: perl,cgi and apache woes
by vinforget (Beadle) on Oct 03, 2003 at 17:23 UTC
    Thanks for the help. After some searching(and asking) I came up with the same. Turns out that there ws nothing wrong with the way I had written my code... just that sometimes perl code written for Apache1.x may not work on Apache2. Vince