#!/usr/local/bin/perl5 -w
#  Simple Translation tr Example
#
use English; # Nicer PERL Labels
#
require "cgi-lib.pl"; # Public Domain library to read form data
#
$statusofread =  &ReadParse(*formdata); # read data in associate array formdata
#
if( $statusofread )     { # If $statusofread nonzero, data read OK
	$inputline = $formdata{"line"}; # Line to interpolate in
	$old = $formdata{"old"}; # old pattern
	$new = $formdata{"new"}; # new pattern
	$modifiers = $formdata{"modifiers"}; # substitution modifiers
	$old =~ s/[;%]//g;
	$new =~ s/[;%]//g;
	$modifiers =~ s/[;%]//g;
}
else	{ # Error Found!
	print <<EOF; # Start the HTML responding page beginning with HTTP line
Content-Type: text/html

<html>
<head>
<title>Data Input Error!</title>
</head>
<body bgcolor="white" >
<h2>There was a Data Input Error -- Sorry</h2>
</body>
</html>
EOF
	exit; # End Program
}
#
$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 Translation tr CGI Script </title>
</head>
<body bgcolor="white" >
EOF
$fred = $inputline;
eval "\$count =(\$fred =~ tr%$old%$new%$modifiers);";
print "Eval Error Message:$EVAL_ERROR</b>\n" if($EVAL_ERROR);
print <<EOF; # Results of Translation
<font size=7>
<b><font color=red>Original    line:</font>$inputline</b><br>
<b><font color=red>Translated  line:</font>$fred</b><br>
<b><font color=red>tr returns count:$count</font></b>
</font>
</body>
</html>
EOF
exit; # End Program
