#!/usr/local/bin/perl5 -w
#  Simple Substitution 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
#
$two = "A firm 2"; # Cant be Changed
if( $statusofread )     { # If $statusofread nonzero, data read OK
        $one = $formdata{"one"}; # The input $one
	$inputline = $formdata{"line"}; # Line to interpolate in
	$old = $formdata{"old"}; # old pattern
	$new = $formdata{"new"}; # new pattern
	$modifiers = $formdata{"modifiers"}; # substitution modifiers
	$one =~ s/[;%]//g; # Remove dangerous characters
	$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 Substitution CGI Script </title>
</head>
<body bgcolor="white" >
EOF
$fred = $inputline;
$A= ' '; $B= ' '; $C= ' ';
eval "\$fred =~ s%$old%$new%$modifiers;\$A=\$`;\$B=\$MATCH;\$C=\$POSTMATCH";
print "Eval Error Message:$EVAL_ERROR</b>\n" if($EVAL_ERROR);
print <<EOF; # Results of Substitution
<font size=7>
<b><font color=red>original    line:</font>$inputline</b><br>
<b><font color=red>Substituted line:</font>$fred</b><br>
<b><font color=red>\$PREMATCH:</font>$A <font color=red>\$MATCH:</font>$B <font color=red>\$POSTMATCH:</font>$C</b>
</font>
</body>
</html>
EOF
exit; # End Program
