Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

problems with CGI module's command line debugging

by 7stud (Deacon)
on Apr 04, 2014 at 19:55 UTC ( [id://1081188]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

According to the CGI.pm docs here: CGI.pm you should be able to execute a CGI script from the command line like this:

your_script.pl name1=value1&name2=value2

However, with the following pragmas:

use CGI qw{:standard -debug};

using the above format for the form variables does not work: my perl script hangs after showing the output for the first name/value pair. Here is the output:

~/perl_programs$ ./my_prog.pl name1=value1&name2=value2 [1] 462 ~/perl_programs$ Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <ul> <li><strong>name1</strong></li> <ul> <li>value1</li> </ul> </ul> </body> </html>(HANGS RIGHT HERE!!)

If I add the pragma:

use CGI qw{:standard -debug -oldstyle_urls};

as explained here: pragmas, the same thing happens.

I am able to get this format to work:

./my_prog.pl name1=value1 name2=value2

i.e. using a space instead of an & as the separator between name/value pairs:

~/perl_programs$ ./my_prog.pl name1=value1 name2=value2 Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <ul> <li><strong>name1</strong></li> <ul> <li>value1</li> </ul> <li><strong>name2</strong></li> <ul> <li>value2</li> </ul> </ul> </body> </html>~/perl_programs$

I also can't get the semi-colon separator to work correctly using the -newstyle_urls pragma:

~/perl_programs$ ./my_prog.pl name1=value1;name2=value2 Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <ul> <li><strong>name1</strong></li> <ul> <li>value1</li> </ul> </ul> </body> </html>~/perl_programs$
Here is the test program I'm using:
#!/usr/bin/env perl use strict; use warnings; use 5.014; use CGI qw{:standard -debug -newstyle_urls}; #Cycling through various + pragmas my $q = CGI->new; print $q->header, $q->start_html; print Dump; print $q->end_html;

Other info:

$ perl -v This is perl 5, version 16, subversion 0 (v5.16.0) built for darwin-2l +evel Copyright 1987-2012, Larry Wall ... $ perl -MCGI -e 'print $CGI::VERSION' 3.59

Replies are listed 'Best First'.
Re: problems with CGI module's command line debugging
by Your Mother (Archbishop) on Apr 04, 2014 at 20:40 UTC

    I think all you're missing is quotes. You can't pass &s and ;s on the shell and expect it to act like simple strings.

    ~/perl_programs$ ./my_prog.pl 'name1=value1&name2=value2'

      Thanks for taking a look Your Mother. Your solution works for me using the pragma:

      use CGI qw{:standard -debug};

      Then I can use all the formats shown in the CGI docs as long as they are surrounded by quotes. As a result, the CGI docs need patching. Do you have the ability to submit a patch? I do not. I've tried it before, and I spent all day and got nowhere.

        Even you can Open Source. :P

        What I suggest–

        • You can find the repository https://github.com/markstos/CGI.pm/tree/master from reading the Makefile.PL at https://metacpan.org/pod/CGI -> Browse -> ../ -> Makefile.PL
        • Get or make sure you are signed-in to a github account.
        • Click on "Fork" on the github page -OR- visit https://github.com/markstos/CGI.pm/blob/master/lib/CGI.pm#L7451 and click "Edit" (back at the top of the page) which forks for you and opens an editor to the right area of the file. (You may have to reload this URL depending on your browser.)
        • Add in text in the paragraph along these lines-
          • Your command line will probably require you to quote your arguments. Single quote bash-style arguments are shown in the examples.
        • Edit the various command lines along these lines-
          • your_script.pl 'name1=value1&name2=value2'
        • "Propose file change" and add your rationale for doing so.

        Update your résumé (patched CGI.pm documentation, assuming it's accepted) and watch yourself become a part of Perl history!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1081188]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found