mwerner92 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI calculator
by GrandFather (Saint) on Jul 07, 2016 at 02:38 UTC | |
|
Re: CGI calculator
by hippo (Archbishop) on Jul 07, 2016 at 08:05 UTC | |
|
Re: CGI calculator
by duyet (Friar) on Jul 07, 2016 at 10:03 UTC | |
|
Re: CGI calculator
by Anonymous Monk on Jul 07, 2016 at 01:47 UTC |