Follow up on 'Could you critique...'
#!/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 }
Just my thoughts :-)

In reply to Re: HTTP headers and redirection by nedals
in thread HTTP headers and redirection by student

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.