in reply to HTTP headers and redirection
Just my thoughts :-)#!/usr/bin/perl use strict; # prevent Perl from creating undeclared variables AND con +trol variable scope use CGI qw(:standard -debug); use CGI::Carp(qw/fatalsToBrowser/); ## Fatal Errors to Browser for de +bugging 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 <form> data to ensure it is wha +t 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 som +ething # } ## 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{'Ra +te'}) { print "Location: http://carrotcake.nsm.tridenttech.edu/c12ex3b.htm +l\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 <<HTMLPAGE; <HTML> <HEAD><TITLE>Patton Industries</TITLE><BASEFONT SIZE=5></HEAD> <BODY> <H1>Bonus Calculation</H1> <!-- this was in the wrong place --> Salesperson: $cgi_vars{'Salesperson'}<BR> Your bonus is: $bonus<BR><BR> You entered a sales amount of $sales and a bonus rate of $rate </BODY> </HTML> HTMLPAGE }
|
|---|