#!/usr/bin/perl
# w5.15.pl Study the subroutine:  "&read_form_results"
# Usage:  codedata.pl | w5.15.pl


&read_form_results

foreach (keys(%entry)){

    print " key is $_\n   $value is $entry{$_};"
}
	



# Sub accepts data stream from STDIN; splits name/value pairs,
# and assigns value to the associative array %entry with name as key
# Courtesy of Russ Nelson.
sub read_form_results {
     local ($buffer, $name, $value);
     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
     foreach (split(/&/, $buffer))                                         
     {
             ($name, $value) = split(/=/);             # Un-Webify plus signs and %-encoding 
             $value =~ tr/+/ /;
             $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;     
             $entry{$name} = $value;
     }
     1;                                                              
}

