#!/usr/local/bin/perl5 -w
#  Simple Basic Read a File Example
#
$today =`date`;
chomp($today); # Today's date captured from UNIX
#
print <<EOF; # Generate the HTML responding page starting with HTTP line
Content-Type: text/html

<html>
<head>
<title>This is Result of my Basic Perl Input CGI Script </title>
</head>
<body bgcolor="white" >
<h1>This Script reads and Writes a cannedfile on a great $today</h1>
<font color=red size=7 > 
EOF
#
open(CANNEDFILE,'<cannedfile') || die("Cannot open designated input file\n"); # Open file or die
#
# Loop over input lines
while( $line=<CANNEDFILE> )	{
	chomp($line); # remove end of line character(s)
	$line = &tohtml($line); # Convert any special HTML characters
	print "$line<br>\n"; # Note for HTML need <br> to get a newline!
}
print <<EOF; # Generate End of HTML Page
</font>
</body>
</html>
EOF
exit; # End Program
#
sub tohtml      { # Convert HTML magic characters  & < > "in current line
        my($convline)=@_;

        return($convline)       unless $convline;
        $convline =~ s/&/&amp;/g;
        $convline =~ s/</&lt;/g;
        $convline =~ s/>/&gt;/g;
        $convline =~ s/"/&quot;/g;
        $convline; # do not need a return
}
