#!/usr/bin/perl -Tw

$query = "bob=rock&joe=rock&tom=notrock";

($query = $ENV{'QUERY_STRING'}) or &err_noquery ;

foreach $bitowork (split(m/\&/, $query)) {
	$bitoname = '';
	$bitovalue = '';
	($bitoname, $bitovalue) = (split( m/=/, $bitowork));
	#Run a subroutine to decode the URL encoding.#
	$bitovalue = url_decoding($bitovalue);
	$bitoname = url_decoding($bitoname);
	#Anouther bit of code whose purpose I am a little unsure of.#
	#I belive that it ensures that the line contains only#
	#certian acceptible characters, some sort of security.#
	if ($bitoname =~ /^[a-zA-Z0-9_]*$/ ) {
		$varname = "qs_$bitoname";
		$$varname = "$bitovalue";
	}
}

sub diag_exit {
    exit -1;
}

sub err_noquery {
    print"Error, no Query</BODY></HTML>";
    @diag_exit;
}

sub url_decoding {
	#This bit of decoding is borrowed from a contribution to 
	#Webglimpse which I believe as writen by Peter Bigot, although
	#the actual code appears to have been added by someone else.
	local($_) = @_;
	s/\+/ /g;
	s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
	return $_
}