Demo of HTML code and CGI implemented using PERL

by Brandon Cantillo

Please enter your name:

Please enter a value for x:

Please enter a value for y:



Select from the following Operations:

+
-
*
/


 

This functionality is accomplished by the following HTML code:

 

<HTML><HEAD><TITLE>CGI Test</TITLE></HEAD>

<CENTER><H1><U>CGI Test</U></H1></CENTER>

<CENTER><H3>by Brandon Cantillo</H3></CENTER>

<html>

<body>

<form action="form.cgi">  // This calls the CGI file to implement the active functionality using PERL

<PRE>Please enter your name:</PRE>

<input type="text" name="name"></input>

<PRE>Please enter a value for x:</PRE>

<input type="text" name="xval" size=1></input>

<PRE>Please enter a value for y:</PRE>

<input type="text" name="yval" size=1></input>

<br>

<br>

<br>

<PRE>Select from the following Operations:</PRE>

<input type="radio" name="operation" value="+" size=1></input>

+

<br>

<input type="radio" name="operation" value="-" size=1></input>

-

<br>

<input type="radio" name="operation" value="*" size=1></input>

*

<br>

<input type="radio" name="operation" value="/" size=1></input>

/

<br>

<HR>

<input type="submit" name="submit" value="submit"></input>

<br>

</form>

</body>

</html>

 

It then calls the following PERL code:

 

#!/usr/bin/perl

#

#

use CGI qw(param);

$header = "MIME-Version: 1.0\n";

$header .= "Content-type: text/html\n";

$header .= "\n";

 

#get the parameter "fname"

$name1 = param("name");

$xval = param("xval");

$yval = param("yval");

$operation = param("operation");

 

#get the current time

$time = scalar localtime;

 

#must print in HTML form to ensure proper formatting.

print "$header<h1>Hello, $name1 ! How are you today?</h1><br>The time is: $time";

print "<br>";

print "<br>";

print "<br>";

print "\n","X = $xval";

 

print "<br>";

print "<br>";

print "\n","Y = $yval";

print "<br>";

print "<br>";

 

 

 

if ($operation eq "+")

   {  

      print "\n","X plus Y is ",$xval+$yval,".";

   }

if ($operation eq "-")

   {  

      print "\n","X minus Y is ",$xval-$yval,".";

   }

  

if ($operation eq "*")

   {

      print "\n","X times Y is ",$xval*$yval,".";

   }

  

if ($operation eq "/")

   {

      print "\n","X divided by Y is ",$xval/$yval,".";

   }