How to debug the perl via cgi?

Posted on 2005-05-17
Medium Priority
Last Modified: 2010-03-05
I am calling perl program from a web. When there is a problem, the error returns page cannot be displayed.
How i can generate meaning error and see for debug?
Question by:StanleyLMW
  • 3
  • 3
  • 2
  • +3
LVL 19

Assisted Solution

by:Kim Ryan
Kim Ryan earned 400 total points
ID: 14016776
If you add the following to your code, you will get more detailed error messages appearing in the browser
use CGI::Carp 'fatalsToBrowser';
LVL 16

Expert Comment

ID: 14017056
...or you can check your webserver error logs to see the details.
LVL 28

Expert Comment

ID: 14019617
use warnings;
use diagnostics;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;

warningsToBrowser(1);   # this goes after you print the header
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 85

Expert Comment

ID: 14024929
You might also try calling the program from the command line using the same parameters that cause the error, so you can use the Perl source debugger.

Author Comment

ID: 14025256

teraplane solution is perfect.

FishMonger, i got errors simply using use warnings. not sure why.
use diagnostics my perl cannot reconize.
LVL 85

Expert Comment

ID: 14025920
if you're not sure why you get warnings, that could indicate a problem.
You should determine he cause of the warnings and try to eliminate them.
If you don't understand the error messages, post them here along with the code,
and we may be able to help you interpret them.

Author Comment

ID: 14034194

use CGI::Carp 'fatalsToBrowser'
this seems could capture the syntax error for me.
However, if there is run time error, it cannot give me clue.

e.g. i have database call with incorrect sql. It just gives me the page not found.
LVL 16

Expert Comment

ID: 14034241
Does the runtime error occur everytime, or for selected user-inputted values??
If the answer to the above is "selected values", you should be putting a lot of checks to first make sure that the database call you are making is valid. Putting user-supplied fields straight into your sql makes your code prone to sql injection attacks.

If the error occur always, follow the advice given in http:#14024929


Accepted Solution

lovesnakeyjakey earned 1400 total points
ID: 14035050
Hello there.
I have found the following very useful in debbugging CGI scripts. Put it at the top of cgi programme before anything else.

#!/usr/local/bin/perl -T

     use CGI::Carp qw(carpout);
     open(LOG, ">/usr/path_to_directory_that_webserver_has_permissions_to_write_to/mycgi.$$.log") or
       die("Unable to open mynewcgi-log: $!\n");

Remember to:
1) change the path and filename to suit your system
2) Once you have finished debbugging your cgi and your happy with it. Remove the BEGGIN statement.

I think this should catch all errors or has all of mine in the past.

Hope this helps.


Author Comment

ID: 14043520

Hi lovesnakeyjakey , it works! so great!
In my case, i cannot use -T, i dont know why. But without -T still work. What does -T means?

LVL 85

Assisted Solution

ozo earned 200 total points
ID: 14043769
perldoc perlrun
       -T   forces "taint" checks to be turned on so you can test them.  Ordi-
            narily these checks are done only when running setuid or setgid.
            It's a good idea to turn them on explicitly for programs that run
            on behalf of someone else whom you might not necessarily trust,
            such as CGI programs or any internet servers you might write in
            Perl.  See perlsec for details.  For security reasons, this option
            must be seen by Perl quite early; usually this means it must
            appear early on the command line or in the #! line for systems
            which support that construct.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question