Gossamer Forum
Home : Products : Gossamer Links : Discussions :

question about a new subroutine

Quote Reply
question about a new subroutine
I created a subroutine to return different 'prices' for every link and I wanted to ask if this might become a processor problem or if someone has another idea to handle this. Would be nice if you could take a look at the code.
Any comments are appreciated.

sub price {
my ($sth,$dbh);
my (@ary);
my $customer = $_[1] || "standard"; # the individual status of each customer bronze,silver,gold
my $customer_factor = undef; # the factor of the customer dependant on the status
my $price = $_[2]; # the price from the database
my $price_discount = $_[3] || 1; # the class depenadant on the product
my $price_currency = $_[4] || "EUR_net"; # the currency factor e.g. 1.95583 for EURO
# the basic customer gets the regular price from the database
if ( $customer eq 'standard') { $customer_factor = 1; }
# if the customer is not standard we try to find his status in the prices database
# and return the customer_factor if we do not find anything we handle him like standard
else {
$dbh = DBI->connect ($SHOP{dsn}, $SHOP{user_name}, $SHOP{password}, { RaiseError => 1 });
$sth = $dbh->prepare (qq{SELECT * FROM shop_Prices WHERE Customer LIKE '$customer'} );
$sth->execute ();
while (@ary = $sth->fetchrow_array ()) { $customer_factor = $ary[$price_discount]; }
$sth->finish ();
$dbh->disconnect ();
unless ($customer_factor) { $customer_factor = 1 };
my $return_price = undef;
# now we can calculate the price and return the result
if ($price_currency eq "DM_net") {$return_price = sprintf ("%0.2f",$customer_factor * $price * 1.95583);}
elsif ($price_currency eq "EUR_net") {$return_price = sprintf ("%0.2f",$customer_factor * $price);}
elsif ($price_currency eq "DM_gros") {$return_price = sprintf ("%0.2f",1.95583 * sprintf ("%0.2f",$customer_factor * 1.16 * $price));}
elsif ($price_currency eq "EUR_gros") {$return_price = sprintf ("%0.2f",$customer_factor * 1.16 * $price);}
return "$return_price";

The routine is called with:


Quote Reply
Re: question about a new subroutine In reply to
Typically, providing dynamic calculations will use more "cycles" (memory/RAM/CPU) than updated columns in the database.

From the looks of your codes, I don't see any glaring problems.


Eliot Lee
Quote Reply
Re: question about a new subroutine In reply to
Hi Eliot Lee,

thank you for your reply and comments.
We do not have our own server and so our space for the database is limited to 100 MB. So we always have to consider how to store the data.