#!/usr/bin/perl use strict; # prevent Perl from creating undeclared variables AND control variable scope use CGI qw(:standard -debug); use CGI::Carp(qw/fatalsToBrowser/); ## Fatal Errors to Browser for debugging my $q = new CGI; ## Declare a CGI object my %cgi_vars = $q->Vars; ## Read all your form variables into a hash in one shot. # It's always a good idea to check any
data to ensure it is what you expect. # ie: Assuming rate is supposed to be an integer for example # if ($cgi_vars{'Rate'} =~ /$\d+$/) { # all is well # } else { # That's not what's expected, so return an error message or something # } ## calculate bonus rates using the $cgi_vars hash instead of declaring lots of new variables my $bonus = $cgi_vars{'Rate'} * $cgi_vars{'Sales'}; if (!$cgi_vars{'Salesperson'} || !$cgi_vars{'Sales'} || !$cgi_vars{'Rate'}) { print "Location: http://carrotcake.nsm.tridenttech.edu/c12ex3b.html\n\n"; ## The elsif's are not required. You do it all here } else { ## Try to keep your Perl and HTML seperated as much as practical $bonus = sprintf("%.2f", $bonus); my $sales = sprintf("%.2f", $cgi_vars{'Sales'}); my $rate = sprintf("%.1f", ($cgi_vars{'Rate'}*100)); print $q->header(); ## using the CGI module to ouput the required HTTP header ## Using 'here-is' to ouput the HTML makes it easier to read print < Patton Industries

Bonus Calculation

Salesperson: $cgi_vars{'Salesperson'}
Your bonus is: $bonus

You entered a sales amount of $sales and a bonus rate of $rate HTMLPAGE }