The 90's called... they want their code back...

merlyn on 2006-01-10T08:20:17

From a recent comp.infosystems.www.authoring.cgi post:

sub ParseForm 
    { 
    my ($key, $prefs, $buffer); 
    if ($ENV{'REQUEST_METHOD'} eq 'GET') 
        { @pairs = split(/&/, $ENV{'QUERY_STRING'}) } 
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') 
        { 
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); 
        @pairs = split(/&/, $buffer) 
        } 
    else {Error('Bad or Unknown Request Method', 
                "The form's request method must be either 'POST' or 
'GET'. Please check your HTML.")} 

foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///mg; $FORM{$name} = $value; ...
And the horror doesn't stop there, but I wanted to minimize your exposure. This is 2006, right?


I'm guilty...

Lunchy on 2006-01-10T14:48:01

That code is pretty close to the form parser that was in the "CGI Programming with Perl" book and I've been using it for a while. *blush* Of course, I do VERY little CGI work and even when I do, it's usually just a quicky. But out of curiosity...what would you recommend instead of a form parser like this. Something in CGI.pm?

Easy - use CGI.pm

SuperCruncher on 2006-01-10T16:18:59

Use the CGI module:
use CGI;

my $cgi = CGI->new();

my $foo_param = $cgi->param('foo');
my $bar_param = $cgi->param{'bar');
Obviously CGI.pm can do a lot more, but that's enough to get you started.