[thelist] Perl program question

Bill Moseley moseley at hank.org
Sun Jun 11 11:03:09 CDT 2006


On Fri, Jun 09, 2006 at 12:49:38PM -0400, Portman wrote:
> I wrote a Perl program for a client a while ago and she recently called 
> me to say that it is not calculating the shipping correctly.  The 
> shipping is calculated by taking a percentage of the total (depending on 
> location) plus a $5 shipping and handling fee.

    my $shippingCharge=$shipcost{$selectedState}*$1+5;

what does "warn total = [$1]\n"; show?

What's $1?

Sorry to be so blunt, but that script is really poorly written.  No
wonder it's hard to see what's not working correctly.

Separate your html generation from your business logic, for starters.
Get your data into and out of a database.  Write the scripts so they
can be run and tested outside of the CGI environment.   Validate all
user data.

    my $deflection=$q->param('deflection');
    my $freeLength=$q->param('freeLength');

    if ($deflection == 0) {$deflection=1;}
    if ($freeLength==0) {$freeLength=1;}

How do you know $q->param('deflection') is numeric, a valid range,
or even defined?


If you want to code web applications in Perl take a look at Catalyst, a
Rails-like MVC framework.  It will help with good coding practices.


-- 
Bill Moseley
moseley at hank.org




More information about the thelist mailing list