Scott R. Godin wrote: > I'd like to create a quantity discount table based on the following > criterion > > quantity 1 - 9 0% > quantity 10 - 19 25% > quantity 20 - 199 40% > quantity 200 - 499 50% > quantity 500+ 55% > > > I'd like to read it in via a __DATA__ handle, and perform the discount > calculation based on the total # of items (out of 6 individual items, > each priced differently but contributing to the total quantity towards > the discount percentage). > > what are some perlish ways one would go about performing this > calculation efficiently ? >
See Jeff's answer as to how to code it up. But I would suggest separating the min/max quantity fields, assuming there is no backwards compatibility reason to keep them together, to me it is a better design not to have to use a regex just to separate what should likely be two fields. They can always be put back together easily but you are less likely to do this frequently, if ever, and you are likely to do the separation *a lot*. Another suggestion would be to store your percentages as a number between 0-1 rather than as an "actual percentage", then you can just multiply by the number directly rather than having to divide by 100 each time. Same efficiency assumption, you will show the percentage as a human readable percentage less frequently then you will do the actual calculations. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>