> if ( $freq eq 'w' ) { > return 1 if ( ($tweek - $dweek) <= 1 ); > } elsif ( $freq eq 'eow' ) { > return 1 if ( ($tweek - $dweek) <= 2 ); > } elsif ( $freq eq 'm' ) { > return 1 if ( ($tweek - $dweek) <= 5 ); > } elsif ( $freq eq 'eom' ) { > return 1 if ( ($tweek - $dweek) <= 8 ); > } else { > return 0; > } > }.
Consider the Switch module, a standard lib since 5.6 (I think). perldoc Switch Also, you could consider moving the calculation outside of the if/elsif/else structure. The only time you don't do it is when an invalid period is selected... and when that happens you probably want to die() or croak() rather than quietly return 0. Include "return 0" as the default. > This works great, except if "today" were sometime in the new year. > Then I'm comparing week 52 to week 3. > > Can anyone offer suggestions on how to calculate those frequencies > across years? Simple maths, calculate (YR * 12) + WK. However, your real problem is when you have week 53. I think you need to only accept the same or next year for today, and make adjustments if week 53 crops up. Jonathan Paton -- #!perl $J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13 17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4 00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/( \d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>