Thanks for a succinct answer. Obviously, I would need to ensure that the appropriate parameters are prefixed ("--") to support GetOptions.
Your answer raises two further questions if you'll indulge me:
-why the different handling of arguments re: command line vs CGI -- and where, if anyplace, is that documented? I read and looked up references for 'parameters' and 'arguments' for a full day before I posted the question, and didn't see anything that hinted at the issue;
-could you possibly explain the REALLY bizarre CGI response when I test-run your logic on Win32 and my ISPs SUN server?
use CGI;
my $qry = new CGI;
my $argCt = @ARGV;
for ($i=0; $i < $argCt; $i++)
{
print "Arg $i = [$ARGV[$i]]\n";
}
print "No args found\n" if $argCt == 0;
foreach my $key ( $qry->param )
{
if ( $qry->param($key) )
{
foreach my $value ( $qry->param($key) )
{
print "key, value are $key, $value\n";
}
} else
{
# arg-less booleans
print "key-only is $key\n";
}
}
print "Arg(0) is [$ARGV[0]], param list is [", $qry->param(),"]\n";
which given the following command lines, produces the given output:
perl stuff.pl a b c
Arg[0] = a
Arg[1] = b
Arg[2] = c
key, value are keywords, a
key, value are keywords, b
key, value are keywords, c
Arg(0) is [a], param list is [keywords]
but
perl stuff.pl a b=
Arg[0] = a
Arg[1] = b=
key-only is a
key-only is b
Arg(0) is [a], param list is [ab]
Note that the "arg-less" booleans appear to have values until ONE value is either specified, OR an "=" trails the value??? (As you noted, on the SUN/OS webserver, the arguments are undefined; the wierd "keywords" 'parameter' happens both on the Win32 command line AND when I run this on the website via the browser with
http:...stuff.cgi?a&b
Thanks!
|