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