http://www.perlmonks.org?node_id=605889


in reply to Debugging CGI/PERL

I've been here, and it's sometimes difficult. However you should try the -debug option available on the CGI pacakges... Of course I'm assuming you're using that.

Use the following use statement to enable debugging:

use CGI qw/:standard -debug/;

Then run the cgi through perl using the debugger settings:

perl -d mycgi.pl

Then you will have to pass cgi parameters. As value pairs. The perldoc for CGI goes into this -- search for 'debugging'.

Also, if there's a point in the flow that you come back to for debugging, you could write out the CGI context to a file . Then subsequently read that context back in to bring you back to a point where you want to debug. restore_parameters is documented in the perldoc.

Finally, and this one takes a little work, but you could possibly force the perl/tk debugger to come up. First you would have to start out your cgi with the following shebang:

#! perl -d:ptkdb

HOWEVER. For this to work you would have to allow any xwindow display to open on your desktop. And you would have to have the DISPLAY environment variable set for apache or by apache before the CGI is invoked... It's hard to setup, but it would give you the best debug situation you could imagine.

It would also help if you had a few

$DB::single=1;
lines scattered through the code that you want to debug.

Just a few thoughts that might get you where you want to be.

Hazah! I'm Employed!

Replies are listed 'Best First'.
Re^2: Debugging CGI/PERL
by tonyc (Pilgrim) on Mar 22, 2007 at 02:28 UTC

    For debugging with ptkdb you can put the setting of DISPLAY in a BEGIN block:

    BEGIN { $ENV{DISPLAY} = '192.168.32.50:0' }

    since ptkdb doesn't try to display a window until after compilation is complete.