#!/usr/local/bin/perl5 -w
#  Simple index and rindex Example
#
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
        $string = $formdata{"string"}; # The input $string
        $substring = $formdata{"substring"}; # The input $substring
        $firstlastloc = $formdata{"loc"}; # The input $firstlastloc
}
#
$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 index and rindex CGI Script </title>
</head>
<body bgcolor="white" >
<font color=red size=7 >
<pre>
$string
1....5....0....5....0....5....0....5....0....5....0
</pre>
EOF
if( $firstlastloc ne '' )	{
	$loc1 = index($string,$substring,$firstlastloc);
	$loc2 = rindex($string,$substring,$firstlastloc);
}
else	{
	$loc1 = index($string,$substring);
	$loc2 = rindex($string,$substring);
}
print "Result of index call is $loc1<br>\n";
print "Result of rindex call is $loc2<br>\n";
print <<EOF; # End HTML Page
</font>
</body>
</html>
EOF
exit; # End Program
