
Jasmine
Administrator
/ Moderator
Apr 10, 2000, 2:55 PM
Post #2 of 2
(423 views)
|
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>"; $subtotal+=$price; } print "Your subtotal is $subtotal"; </pre><HR></BLOCKQUOTE> The += increments subtotal by price through each iteration of the loop. Hope this helps!
|