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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.