Re: new to Perl - please verify my script?



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
.



Relevant Pages

  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)
  • Re: compare values in the same field in consecutive rows--and store the result in an array
    ... When the next match is found, store the two values in ... fields in consecutive rows. ... You should use an array for the "p" field values if you to need to ...
    (comp.lang.awk)
  • Re: Was this a bug
    ... that you didn't store in memory somewhere ... outside the array that you were trying to store in? ...
    (comp.lang.fortran)
  • Re: THATS IT !!
    ... and threw away the store. ... That's an intelligent compiler. ... lot of work to find out that an array element is ...
    (sci.crypt)
  • Urgent Enquiry
    ... The manager of JOE MARK STORE INC. ... Am here to order for some of your products to my New Store that just open to West Africa. ... Plesae let me know the shipping Rate to my New store at Abidjan Cote D Ivoire. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)