Monday, December 05, 2005
Perl: CGI example
Continuing with our script, remeber that we had an array of strings that
contained the CGI name/value pairs. Now we'll iterate through them and
create an associative array for easy manipulation later.
foreach $pair ( @cgiPairs ) {
($var,$val) = split("=",$pair);
#trust me on this magic.
$val =~ s/\+/ /g;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$cgiVals{"$var"} = "$val";
}
$recipient = $cgiVals{"to"};
The magic included in the fourth line is to decode the special characters
that aren't allowed to be in a URL. For now, please take it on trust.