Forum Moderators: coopster & phranque

Message Too Old, No Replies

First time at Perl / Cgi

Doctoring a current script

         

stuart

4:14 pm on Apr 3, 2003 (gmt 0)

10+ Year Member



Hi, I've worked out whats going on in most of a form to email script but can anyone tell me roughly what this bit is about:

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;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}

$mailprog = "/usr/lib/sendmail";

TIA and apologies if its a daft question. Just finding my way.

Stuart

SinclairUser

4:37 pm on Apr 3, 2003 (gmt 0)

10+ Year Member



Stu,

------ read in posted data from stdin ------
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

------ put name=value pairs into array -----
@pairs = split(/&/, $buffer);

----- for each pair get the name and value ---
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;

----- store the name value pairs in a hash ---
$FORM{$name} = $value;

Is that what you want?

andreasfriedrich

4:40 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code reads the data posted by the FORM [w3.org] to STDIN and parses it into key => value pairs that are available via the $FORM hash.

The line containing pack [perldoc.com] url_decodes the data.

Andreas

<added>Too slow again</added>

stuart

4:58 pm on Apr 3, 2003 (gmt 0)

10+ Year Member



Fantastic, thanks. Exactly what i needed, now to printer friendly and back to the lessons. Thanks very much.