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

Hello, I'm using strict and warnings in the perl program , However strict getting included without any errors but it doesn't helping with debugging at all. Here what i'm testing,
#!/usr/bin/perl use strict; use warnings; use CGI; my $test = new CGI; print $test->header("text/html"); $test->start_html("Perl Test") print $test->h1("Perl is working!"); print $test->end_html;
As this script has syntax error i expected some kind of error as output as i'm using strict and warnings, but instead of it is showing 502 error at server no matter what's the error.

Here what it shows , http://postimg.org/image/5ksy74oil/

I have searched a lot about solution and failed. so i had no choice but asking in community. Any help will be highly appreciated.

Replies are listed 'Best First'.
Re: Perl Strict 502 Error No DEBUG SUPPORT
by fishmonger (Chaplain) on Mar 27, 2015 at 20:22 UTC

    The error message you're expecting to see is being sent to STDERR which need to be redirected to be able to see it in the browser. In order to do that, add this use statement:

    use CGI::Carp qw(fatalsToBrowser);

    To be able to also see the warnings (as html comments), you need to adjust that statement to this:

    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

    And, add this statement right after printing the header.

    warningsToBrowser(1);
Re: Perl Strict 502 Error No DEBUG SUPPORT
by MidLifeXis (Monsignor) on Mar 27, 2015 at 20:24 UTC

    A 500 server error indicates that something is wrong with the server. Check your server's error logs, not just the browser.

    --MidLifeXis

Re: Perl Strict 502 Error No DEBUG SUPPORT
by NetWallah (Canon) on Mar 28, 2015 at 04:15 UTC
    Your error is that this line:
    $test->start_html("Perl Test")
    is missing a trailing semicolon.

    You could have discovered that by running your script from the command line, or using "fatalstobrowser" etc from Carp, as suggested earlier.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

Re: Perl Strict 502 Error No DEBUG SUPPORT
by marinersk (Priest) on Mar 27, 2015 at 22:25 UTC

    Strictly to add tools to your web debugging set -- a way to capture your Perl errors when running stuff on a remote web server where you might not have easy access to web logs, you could use evalto write them to a log file (which usually lands by default in your cgi directory but you'll have to sort that one out yourself).

    #!/usr/bin/perl use strict; eval { [... do stuff ...] } ; # End eval{} error trap set REQUIRES a semicolon if ($@) { my $dsperr = $@; my $logsse = time; open ERRLOG, '>>', 'myerror.log'; print ERRLOG "$logsse $dsperr\n"; close ERRLOG; } exit;

Re: Perl Strict 502 Error No DEBUG SUPPORT
by Laurent_R (Canon) on Mar 28, 2015 at 09:46 UTC
    You could also check the syntax by simply use the -c option of the command line:
    $ perl -ce ' > #!/usr/bin/perl > use strict; > use warnings; > use CGI; > my $test = new CGI; > print $test->header("text/html"); > $test->start_html("Perl Test") > print $test->h1("Perl is working!"); > print $test->end_html; > ' syntax error at -e line 9, near ") print" -e had compilation errors.

    Je suis Charlie.
Re: Perl Strict 502 Error No DEBUG SUPPORT
by Anonymous Monk on Mar 27, 2015 at 22:10 UTC
    http errors aren't perl errors, they're http errors