Re: HTML-Tree

richard@futurefocusinc.com
Sun, 27 Jun 1999 08:40:13 -0700


> i wonder if this shouldn't also be a pre-requisite (or a recommended
> module) for libwww installation, since things like POST use the
> HTML::Parse (as well as the lwpcook.pod, as noted in the changelog)
> 
> Thanks...
> -- 
> Darryl Lee <lee@darryl.com> | New, yes. But improved?
> <http://www.darryl.com>
> 
I've been tinkering w/ perl dev for a short while and I always use the 
subroutine shown below for parsing forms. I saw the posting from 
darryl (above) and was wondering if the HTML::Parse accomplishes 
the same thing??

Any words on this would be greatly appreciated.

Rich - JAPW

sub parseForm
{
	if($ENV{'REQUEST_METHOD'} eq "GET")
	{
		$buffer = $ENV{'QUERY_STRING'};
	}
	elsif($ENV{'REQUEST_METHOD'} eq "POST")
	{
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	}
	else
	{
		print "Unknown REQUEST_METHOD";
		exit();
	}

	# Split the input into name-value pairs
	@pairs = split(/&/, $buffer);

	# Loop through each pair and place the name in the name 	
	#array and the value in the value array
	foreach $pair (@pairs)
	{
	  ($name, $value) = split(/=/, $pair);

  	# Change the pluses into spaces and the hex (% stuff) into real 
	characters
  	$name  =~ s/\+/ /g;
  	$name  =~ s/%(..)/pack("c",hex($1))/ge;
  	$value =~ s/\+/ /g;
  	$value =~ s/%(..)/pack("c",hex($1))/ge;

		# If they try to include server side includes, erase them
		$value =~ s/<!--(.|\n)*-->//g;

  	# Debug the output from this loop
  	# print "Setting $name to $value<BR>\n";
		$final{$name} = $value;
	}
}