Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

debug cgi programs with post forms

1 view
Skip to first unread message

david

unread,
Nov 20, 2008, 4:38:12 AM11/20/08
to
Hi all,

How do i debug cgi programs where the html contains a post form ?
If it contains a get form it is easy because i can run perl -d from
the command line.
In this case i have a very large form with many variables and it is a
post form.
How can i debug it ?
I made a google search and found answers like printing the environment
variables and then run it like a get command with perl -d but this is
a bit tedious.
Is there a "best practice" for this type of problem ?


Thanks in advance,
David

sopan....@gmail.com

unread,
Nov 20, 2008, 5:02:26 AM11/20/08
to
Try using Data::Dumper module.

--------
use CGI;
use Data::Dumper;

my $query= new CGI();
print $query->header();
print Data::Dumper->Dump([$query]);

----------

This should give you all information into your browser.


-Sopan Shewale
(http://sopanshewale.blogspot.com)

smallpond

unread,
Nov 20, 2008, 10:27:17 AM11/20/08
to


http://search.cpan.org/dist/CGI.pm/CGI.pm#DEBUGGING

CGI has a -debug mode that should allow you to emulate POST input
from
the command line. I haven't tried it, so I have no idea what it does
about the CONTENT_LENGTH stuff. The alternative would be to set
CONTENT_LENGTH and open a file of your POST data on STDIN.


xho...@gmail.com

unread,
Nov 20, 2008, 11:27:10 AM11/20/08
to
david <micha...@gmail.com> wrote:
> Hi all,
>
> How do i debug cgi programs where the html contains a post form ?
> If it contains a get form it is easy because i can run perl -d from
> the command line.
> In this case i have a very large form with many variables and it is a
> post form.

Does it have file upload fields?

> How can i debug it ?

What kind of bugs are you looking for?

> I made a google search and found answers like printing the environment
> variables and then run it like a get command with perl -d but this is
> a bit tedious.
> Is there a "best practice" for this type of problem ?

I find the best practice is not making bugs in the first place. :)

I also often add code to the CGI to process secret debugging parameter,
which turns on strategically placed extra print or warn statements.

warn "Now I'm doing $foo" if $cgi->url_param('debug');

If you really want to debug under -d, then you can run the program using
$cgi->save($file_handle) to save the query and then perl -d script.cgi <
saved_query_file

(this won't work with file upload fields, as the file contents are not
saved.)

Where the script use CGI has been changed to something like:
use CGI qw(-debug);

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

david

unread,
Nov 20, 2008, 11:31:54 AM11/20/08
to
I am not using file upload fields, so the option of $cgi->save

($file_handle) to save the query and then perl -d script.cgi <
saved_query_file to run the query will be great

Thank you very much

On Nov 20, 6:27 pm, xhos...@gmail.com wrote:

david

unread,
Dec 9, 2008, 4:12:16 AM12/9/08
to
On Nov 20, 6:27 pm, xhos...@gmail.com wrote:
> david <michaelg...@gmail.com> wrote:
> > Hi all,
>
> > How do idebugcgiprograms where the html contains a post form ?

> > If it contains a get form it is easy because i can run perl -d from
> > the command line.
> > In this case i have a very large form with many variables and it is a
> > post form.
>
> Does it have file upload fields?
>
> > How can idebugit ?

>
> What kind of bugs are you looking for?
>
> > I made a google search and found answers like printing the environment
> > variables and then run it like a get command with perl -d but this is
> > a bit tedious.
> > Is there a "best practice" for this type of problem ?
>
> I find the best practice is not making bugs in the first place. :)
>
> I also often add code to theCGIto process secret debugging parameter,

> which turns on strategically placed extra print or warn statements.
>
> warn "Now I'm doing $foo" if $cgi->url_param('debug');
>
> If you really want todebugunder -d, then you can run the program using

> $cgi->save($file_handle) to save the query and then perl -d script.cgi<
> saved_query_file
>
> (this won't work with file upload fields, as the file contents are not
> saved.)
>
> Where the script useCGIhas been changed to something like:

> useCGIqw(-debug);
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> this fact.

I have now another problem. The $cgi->save($file_handle) does not save
cookie data. How it is possible to work with it when using also cookie
data ?

0 new messages