in reply to Re: Date Ranges Question
in thread Date Ranges Question
GrandFather, the problem seems to be this:
The question from this is: what is the cost of item #1 for a purchase made on March 18th, 2005? For that, you have to scan through looking for the last date key that is less than or equal to the desired date.%partprice = ( 1 => { '2005-01-01' => 1.99, # new year special. '2005-01-02' => 8.99, # back to normal. '2005-02-15' => 9.99, # price bump. '2005-04-01' => 9.49, # on sale. '2005-04-08' => 9.99, # sale's over. }, );
If, however, you had an ordered hash, you could do a binary search for it. Or if you had a tree or something where the date keys were stored in an order, you could look it up faster.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Date Ranges Question
by lamberms (Sexton) on Oct 25, 2005 at 20:08 UTC |