in reply to Why does Getopt::Long ignore browser and SSI-based parameters?
CGIs derive their parameters from either $ENV{'QUERY_STRING'} or <STDIN> (or both!), while Getopt::Long expects everything to be in @ARGV.
Converting one to the other is trivial ...
my $extract; my $file; { local @ARGV = split /&/, $ENV{'QUERY_STRING'}; GetOptions( 'file=s' => \$file, 'extract!' => \$extract, ); }
That'll break if you have URI-escaped characters (ie, %7E instead of ~), so a more robust solution would be to iteratively build @ARGV using CGI's param funcs.
my $extract; my $file; { local @ARGV; foreach my $key ( param ) { if ( param($key) ) { foreach my $value ( param($key) ) { push @ARGV, $key, $value; } } else { # arg-less booleans push @ARGV, $key; } } GetOptions( 'file=s' => \$file, 'extract!' => \$extract, ); }
|
|---|