garymgordon
Programmer
I am very confused (as I am new to Perl) on exactly how the following works.
Especially the part:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
(What in the world is the % doing in there?? And what is pcak("C",hex($1))/eg; ???)
If you would, please explain .. line by line and then almost character by character - what this code snippet is doing.
Thanks.
Here it is:
sub get_form_data
{
# Get the input
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
# Split the name-value pairs
@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/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
}
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
Especially the part:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
(What in the world is the % doing in there?? And what is pcak("C",hex($1))/eg; ???)
If you would, please explain .. line by line and then almost character by character - what this code snippet is doing.
Thanks.
Here it is:
sub get_form_data
{
# Get the input
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
# Split the name-value pairs
@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/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}
}
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer