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

Hi.
How can i see the errors of the scripts CGI using Perl language?
Thanks...

Replies are listed 'Best First'.
(jeffa) Re: See errors in CGI scripts using perl
by jeffa (Bishop) on Jul 24, 2003 at 14:46 UTC
Re: See errors in CGI scripts using perl
by blue_cowdawg (Monsignor) on Jul 24, 2003 at 15:09 UTC

    As jeffa points out use CGI::Carp and look in the server's log files for the errors. Additionally you can use CGI::Carp qw/ fatalsToBrowser / if you don't have access to the server's log files.

    Other techniques you can use involve some sort of trapping of errors and sending them out as html. An example:

      #!/usr/bin/perl -w #################################3 use strict; use CGI; use DBI; my $q=new CGI; my $dbh=DBI->connect("DBI:mysql:dbhost=localhost", "dbuser","secret") or scream_and_die($q,$DBI::errstr); # # more code... # exit(0); sub scream_and_die { my ($q,$str)=@_; print $q->header,$q->start_html(-title=>"UH-OH!"), $q->p("An error occured!"), $q->p($str),$q->end_html; exit(0); }

    The biggest problem with the example I give above is that if you use it in production you possibly can leak sensitive information if something bad happens.


    Peter L. BergholdBrewer of Belgian Ales
    Peter@Berghold.Netwww.berghold.net
    Unix Professional
Re: See errors in CGI scripts using perl
by arthas (Hermit) on Jul 24, 2003 at 17:34 UTC

    Try:

    use CGI::Carp qw(fatalsToBrowser);

    This will display all errors in your browser.

    Michele.

Re: See errors in CGI scripts using perl
by freddo411 (Chaplain) on Jul 24, 2003 at 18:47 UTC
    Another approach to debugging a cgi is to run it from the command line. This assumes that you have shell access to the server you are debugging on. If you don't have shell access, to a production machine perhaps, set up another machine where you do have access that mimics the production machine. To make this somewhat painless, put this into your code:
    use CGI qw/ -debug/;
    then run the cgi from the command line. At this point you'll get:
    (offline mode: enter name=value pairs on standard input)
    and you can type in the parameters ( foo=555 <return> and so on, followed by a <ctrl>D to end). If things aren't going well, you'll see the error messages in your shell. If you cgi spits out a badly formated response, you'll see that. There are other tricks too, read more about it at: CGI Cheers --Freddo411

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

Re: See errors in CGI scripts using perl
by PodMaster (Abbot) on Jul 25, 2003 at 07:12 UTC
    Checkout It's a pretty good tutorial (as are quite a few others in that Tutorials section); It covers practically every trick in the book.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: See errors in CGI scripts using perl
by vek (Prior) on Jul 25, 2003 at 11:39 UTC

    As others have pointed out, CGI::Carp qw(fatalsToBrowser); is what you're after. You will want to use this for development *only* as it is a potential security hole if left in production code.

    Also, check out Ovid's Web Programming Using Perl course.

    -- vek --