1. You say that the week "starts on Monday and ends on a Sunday" yet you provide an example which looks like Tuesday (8-19-03) through Monday (8-25-03). If you can better define what "last week" means, it would be easier to figure out if code met the spec. For example, is "today" ever part of "last week" or is it always the Mon-Sun that is completely before today?
2. You say you have "2 digits each for month, day and year" yet the examples you provide make it look like a single digit is accepted. Does the input you are trying to match have a leading zero for single digit months and days?
3. I don't think /^8\-[19-25]\-03/ does what you want it to. The character class in the middle (surrounded by square brackets) actually matches a single character of "1" or "9" through "5" or "5". The "9" through "5" is also going to be flagged as an invalid range since it starts with something higher than it ends.
4. You don't need to escape dashes (-) outside of character ranges.
5. If a regular expression is really the best approach, I think you are most likely going to end up with one that looks something like this:
This could be reduced by extrapolating the common portions, but you probably would not gain much and this format has the benefit that you can glance at it and know that it matches exactly the days you want.$string =~ /^(7-26-03|7-27-03|7-28-03|7-29-03|7-30-03|7-31-03|8-1-03|8 +-2-03)/
6. Oh, yeah, I'd use Date::Manip to do the date calculations, but that's just because it's the only date manipulation package I've learned, it's portable (completely Perl), and it includes the kitchen sink. Be warned, though, that it's a bit tricky to understand the interface when you're starting out. Examples and testing help a lot.
-- Eric Hammond
In reply to Re: Week Algorithm
by esh
in thread Week Algorithm
by rupesh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |