user828647
user828647

Reputation: 515

Debugging perl CGI

I am using a web form I created as an interface to query a MySQL database. I have written some perl CGI scripts to process the queries. But I am not getting the desired output, so I need to debug the scripts. How do I do that? I mostly use Eclipse for debugging perl, but now I have the web form parameters (checkboxes, listboxes) as input to the script. Is there any way I can pass in the inputs from the web page and then debug the script in Eclipse? Or is there any other way of debugging in this case? Hope I have made myself clear. Thanks.

Upvotes: 2

Views: 3467

Answers (6)

MichielB
MichielB

Reputation: 4295

Yes, of course you can use Apaches error log to do debugging; which a very lazy but efficient way to work.

You mention you use Eclipse so I assume you also use the EPIC plug-in for Perl development. Check out this chapter on how to configure Eclipse/EPIC for debugging CGI:

http://www.epic-ide.org/guide/ch06s02.php

Upvotes: 3

Len Jaffe
Len Jaffe

Reputation: 3484

if you have a hypothetical CGI program written in perl, called webawesome.pl and you want to pass it two parameters: name and age, you can use a shell command like this:

prompt> perl -d webawesome.pl name=sifl age=21

Now you're in the perl debugger and you can step through your program, and the key/value pairs from the command line will be loaded as form parameters by CGI.pm

Setting these command line switches in Eclipse is left as an exercise to the reader, as I am an unabashed vi user, and haven't use eclipse in two or three years. I know there's dialogs to set run/debug options.

Upvotes: 1

w.k
w.k

Reputation: 8376

It's not clear what exactly you want to debug, but a few tips:

Upvotes: 1

Dee Newcum
Dee Newcum

Reputation: 1030

I use this Perl module for CGI debugging. It lets you capture all data sent to a CGI script, when running from a normal browser. It then lets you "replay" the script from anywhere (command line, within a debugger) using the captured data.

CGI::Inspect looks promising, though I haven't tried it yet myself.

Using Devel::DumpTrace during a normal CGI session (with the data being logged to a file, via DUMPTRACE_FH) is a way to do in-depth debugging, without using an actual debugger.

Upvotes: 4

jimtut
jimtut

Reputation: 2393

I would hope Eclipse has a way to simulate CGI.

I use ActiveState's Komodo IDE, and it can simulate CGI (including input params), so I can recommend that as a good tool for this purpose. The IDE is NOT free, though, but consider this an investment if you're going to be doing this a lot. (I'm NOT affiliated with ActiveState - just a happy customer.)

Upvotes: 1

scrappedcola
scrappedcola

Reputation: 10572

You can use Firebug or Fiddler to watch your requests made from the form, to ensure you are sending exactly what you think you are. You can also open a file open(fh,">>debug.txt") and print out the sql calls that you are making to a log file. I would also suggest learning about Data::Dumper which will print out objects prettily so you can see their structure.

Upvotes: 0

Related Questions