cei has asked for the wisdom of the Perl Monks concerning the following question:
When this happens, I normally use the following subroutine:
sub parsedata { ($ENV{'REQUEST_METHOD'} eq "GET") ? $in = $ENV{'QUERY_STRING'} : read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; $in[$i] =~ s/%(..)/pack("c",hex($1))/ge; $in[$i] =~ s/\n/ /g; $in[$i] =~ s/\r/ /g; ($key, $val) = split(/=/,$in[$i],2); $in{$key} .= '\0' if (defined($in{$key})); $in{$key} .= $val; } }
This then makes a variable $in{'foo'} for the HTML form element named foo.
Great.
But I've also started writing use strict in all my code, and it's not real clear to me how I can get my scoping correct using the above function.
Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A strict CGI parser?
by chromatic (Archbishop) on Jul 26, 2000 at 00:58 UTC | |
|
Re: A strict CGI parser?
by athomason (Curate) on Jul 26, 2000 at 01:13 UTC | |
|
Re: A strict CGI parser?
by davorg (Chancellor) on Jul 26, 2000 at 02:08 UTC |