Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to know more about this code:
if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $contents{$name} = $value; } }
I am a complete beginner. I'm using perl to do research for my Master's, and, uh... I'm a little lost. Not quite sure how this code parses from an HTML form if there's a radio button on it. Any help would be most appreciated. -thomas

Replies are listed 'Best First'.
Re: quickform for beginner
by Zaxo (Archbishop) on Sep 20, 2001 at 03:47 UTC

    The code is a query parser for the http POST method. $ENV{} refers to the process environment variable named in the braces. Http servers present POST data on the STDIN filehandle. The innermost block is intended to decode and parse the data. Details of parsing don't look quite right.

    You need to use CGI.pm for this. The learning curve is not too steep and the code quality is exceptional.

    After Compline,
    Zaxo

      I will try this cgi.pm. May god shine down upon you. -thomas
Re: quickform for beginner
by blakem (Monsignor) on Sep 20, 2001 at 03:41 UTC
    hmmmm... that looks like it came from the rather outdated cgi-lib.pl library. I'd recommend upgrading to CGI.pm which is much more robust. cgi-lib.pl fell out of favor quite some time ago.

    -Blake