I'm trying to create a cgi perl script calculator but honestly have no idea where to start and can't get a hold of my teacher.. I have the following html code set up for my apache server saved in /var/www/html:
<html> <head> <title>A Simple Calculator </title> </head> <body> <h1> Welcome to the Training Center Calculator </h1> <form action=/cgi-bin/calc.pl method="get"> Variable 1: <input type="text" name="v1" size = 40 maxlength=40><p> Variable 2: <input type="text" name="v2" size = 40 maxlength=40><p> Choose an action: <br> <input type="radio" name=oper value="Add">Addition<br> <input type="radio" name=oper value="Sub">Subtraction<br> <input type="radio" name=oper value="Multiply">Multiply<br> <input type="radio" name=oper value="Divide">Divide<br> <input type="radio" name=oper value="Exponent">Exponent<br> <p> <input type="submit" value="Submit form"> <input type="Reset" value="Clear all fields"> </body> </html>
I'm just trying to get an idea of where to start. This is all I have for the perl script at the moment:
#!/usr/bin/perl require("cgi-lib.pl"); &ReadParse(*input); print "Content-type: text/html\n\n"; $na = param('v1'); $nb = param('v2'); $oper = param('oper'); $nc; $nd; $expo; $answ; if ($oper == "addition") { $answ = $na + $nb; $nd = "+";
any tips on where to go from here with elsifs and make sure it ties into the html form right, would be greatly appreciated!
In reply to CGI calculator by mwerner92
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |