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

Brethern, I'm puzzled by some behavior I see in the debugger. When I require a file, it doesn't behave as I expect. In detail –

I'm using CGI::Pretty to build screens for editing a data structure. On certain inputs, this was failing with an unhelpful message. To debug it, I wanted to run the program from the line debugger, so I could see the calling stack and so forth. But to re-create the error, I needed to call the cgi script with the same POSTDATA parameters.

So I wrote a small function that wrote all the 'param' parameters to a file:

print "#/usr/local/bin/perl\n"; foreach (param()){ print ("param('$_' , '", param($_), "'\n");}
which, as I intended, wrote a file that looked like
#/usr/local/bin/perl param('p1', 'v1'); param('p2', 'v2');...
I executed the script in the debugger and executed
DB<1> require "mydebugparam.pl" DB<2> x param()
To my surprise, no parameters had been set by reading in mydebugparam.pl. So, hacking on, I wrapped all the param calls in a function definition. I modified the code so it printed out something of the form:
#/usr/local/bin/perl sub sn{ param('p1', 'v1'); param('p2', 'v2');...}
Now I performed
DB<1> require "mydebugparam.pl" DB<2> sn() DB<3> x param()
and saw the parameters set as I had intended.

Why didn't require-ing the param statements work, while wrapping them in a function def did?

Am I going about this all wrong? Is there an easier way to be debugging cgi forms that have large numbers of POSTDATA params?

thanks
throop

Replies are listed 'Best First'.
Re: CGI Params in a scratch file for debugging
by arkturuz (Curate) on Sep 04, 2007 at 20:40 UTC
    Quote: Is there an easier way to be debugging cgi forms that have large numbers of POSTDATA params?

    CGI module might be of better help as it already supports saving and loading params via files.

    BTW, where did you get param() function from? It's not specified anywhere in the CGI::Pretty docs.

      BTW, where did you get param() function from? It's not specified anywhere in the CGI::Pretty docs.
      I'm guessing it comes straight out of CGI, which CGI::Pretty inherits from.
Re: CGI Params in a scratch file for debugging
by Gangabass (Vicar) on Sep 05, 2007 at 01:08 UTC
    print "#!/usr/local/bin/perl\n";

    But this not explain why require did't work without function call :-(