in reply to How Many Mondays in Date Range?

Here is an update that does exactly as you ask (Monday = 1 and Sunday = 7) and iterates a maximum of 6 times - ie it adds initialises the array with int($days/7) and just adds the remaining 0-6 to the appropriate elements. This is as fast and efficient as it gets.

my $days = 72; my $firstday = 5; # for each 7 days each element gets a value of +1 # initialise 8 array elements my @daycounts = (int($days/7)) x 8; $days = $days%7; for my $day_num( ($firstday-1) .. ($days+$firstday-2) ) { $daycounts[1+$day_num%7]++; } # now print it out nice and pretty my %weekdays = ( 1 => Monday, 2 => Tuesday, 3 => Wednesday, 4 => Thursday, 5 => Friday, 6 => Saturday, 7 => Sunday); for my $day_num(1..7) { print "$daycounts[$day_num]\t$weekdays{$day_num}\n"; } # here it is as a one liner $daycounts[1+$_%7]++ for ($firstday-1)..($days+$firstday-2);

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print