Re: new to Perl - please verify my script?
- From: Rob Campbell <news@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Jun 2005 10:13:50 GMT
zig wrote:
<snip>
> if ($item_quantity = "1") {
>
> $ship_total2 = "3.00";
>
>
> }elsif ($item_quantity = "2") {
>
> $ship_total2 = "4.00";
>
>
> }elsif ($item_quantity = "3") {
>
> $ship_total2 = "5.00";
>
> }elsif ($item_quantity = "4") {
>
> $ship_total2 = "6.00";
>
>
> }elsif ($item_quantity > "4") {
>
> $ship_total2 = "6.00";
>
> }
>
I'm sure there'll be other comments, but here's one. It would be neater not
to use these multiple elsif statements. You can store the shipping total
and item quantities in a hash. e.g.
my %item = (1, 3.0,
2, 4.5,
3, 5.5,
4, 6.0);
You can then reference the price using the item quantity. So to see the cost
of shipping 3 items you can just type:
print $item{3} ;
Perl will return "5.5"
You could, just as easily, store these prices in an array where the index of
the number in the array corresponds to the number of items. It notice you
have different shipping rate for different parts of the world. You could
therefore store your shipping rates all in one hash where the values are
not a scalar but an array:
shttp://perldoc.perl.org/perldsc.html#HASHES-OF-ARRAYS
That way
$item{3}[0] might be 3 items to the UK and $item{3}[1] could be 3 items to
Europe, and so on...
<snip>
--
remove FERRET for reply
www.robertcampbell.co.uk
.
- Follow-Ups:
- Re: new to Perl - please verify my script?
- From: Anno Siegel
- Re: new to Perl - please verify my script?
- References:
- new to Perl - please verify my script?
- From: zig
- new to Perl - please verify my script?
- Prev by Date: FAQ 3.5 How do I debug my Perl programs?
- Next by Date: Re: new to Perl - please verify my script?
- Previous by thread: new to Perl - please verify my script?
- Next by thread: Re: new to Perl - please verify my script?
- Index(es):
Relevant Pages
|