CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:



Apr 10, 2000, 12:29 PM

Post #1 of 2 (2420 views)
Calculations Can't Post

I have just started learning perl and have been asked to set up a small online store as an exercise.

Please would you kindly advise me of the most efficient way to do the calculations for the sub-totals and total amount of each purchase. The store items and prices are sourced from a database which is referred to in the perl script. Should the calculations be written as (1.) perl sub-routines (I am aware that this may slow down the process), or should they be (2.)calulated client side ie; javascript within the perl script itself, or (3.)I have got it all wrong? .

I would greatly appreciate any assistance or recommendations in this regard.

Thank You

Administrator / Moderator

Apr 10, 2000, 2:55 PM

Post #2 of 2 (2420 views)
Re: Calculations [In reply to] Can't Post

The most efficient way to calculate subtotals is by incrementing the subtotal at the same time you are looping through your products to display. For example:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

my $subtotal;
foreach (@product){
my ($name,$price,$etc)= split(/|/,$_);
print "Name: $name<BR>";
print "Price: $price<BR>";
print "Your subtotal is $subtotal";

The += increments subtotal by price through each iteration of the loop.

Hope this helps!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives