#!/usr/local/bin/perl5 -w
#  Simple Associative Array Example
#
require "cgi-lib.pl"; # Public Domain library to read form data
#
$statusofread =  &ReadParse(*formdata); # read data in associate array formdata
#
$lhs="subject";
if( $statusofread )     { # If $statusofread nonzero, data read OK
	$lhs = $formdata{'lhs'}; 
	$lhs =~ tr/A-Z/a-z/; # Convert key to lowercase
}
#
$today =`date`;
chomp($today); # Today's date captured from UNIX
#
print <<EOF; # Start the HTML responding page beginning with HTTP line
Content-Type: text/html

<html>
<head>
<title>This is Result of my  Associative Array Perl Script </title>
</head>
<body bgcolor="white" >
<font size=7><b>
<font color=red >
EOF
#
open(MAILHEADER,'<mailheader') || die("Cannot open designated input file\n"); # Open file or die
#
# Loop over input lines
while( $line=<MAILHEADER> )     {
        chomp($line); # remove end of line character(s)
	$line =~ m%^([^:]+):(.*)$%; # Break into two with colon
	$key = $1; # Save matched Patterns in Parantheses
	$rhs = $2;
	$key =~ s/\s*//g; # Remove White Space from Key
	$key =~ tr/A-Z/a-z/; # Convert key to lowercase
	$rhs =~ s/^\s*//; # Remove Leading White Space from rhs
	$rhs =~ s/\s*$//; # Remove Trailing White Space from rhs
	$mailinput{$key} = $rhs; # Store in Associative Array
}
close(MAILHEADER);
if( exists($mailinput{$lhs}) )	{
	if( defined($mailinput{$lhs}) )	{
		print "$mailinput{$lhs} is rhs for key $lhs<br>\n";
	}
	else	{
		print "key $lhs is undefined<br>\n";
	}
}
else	{
	print "$lhs key does not exist<br>\n";
}
print "</font>\n";
foreach $key (keys(%mailinput))	{
	print "$mailinput{$key} is rhs for key $key<br>\n";
}
print <<EOF; # End HTML Page
</b></font>
</body>
</html>
EOF
exit; # End Program
