The following does what you want (safely) using only core modules and core functions:
use POSIX qw( strftime ); use Time::Local qw( timelocal timelocal_nocheck ); my $start = timelocal(0, 0, 0, (localtime)[3,4,5]); # Today my $end = timelocal(0, 0, 0, 1, 3-1, 2006); # March 1st, 2006 my $date = $start; while ($date <= $end) { my @date = localtime($date); my @tomorrow = @date; $tomorrow[3]++; $date = timelocal_nocheck(@tomorrow); my $wday = $date[6]; next if $wday == 0 || $wday == 6; # Weekend # Date in locale-specific format. print(strftime('%x', @date), "\n"); }
Output on my system:
2006/01/20 2006/01/23 2006/01/24 2006/01/25 2006/01/26 2006/01/27 2006/01/30 2006/01/31 2006/02/01 2006/02/02 2006/02/03 2006/02/06 2006/02/07 2006/02/08 2006/02/09 2006/02/10 2006/02/13 2006/02/14 2006/02/15 2006/02/16 2006/02/17 2006/02/20 2006/02/21 2006/02/22 2006/02/23 2006/02/24 2006/02/27 2006/02/28 2006/03/01
References:
Time::Local
POSIX
localtime
The code could be optimized to only call localtime and timelocal to find the last day of the month and the first day of next month. However, the added complexity to the code is not likely to be worth the savings.
In reply to Re: Which Date Module?
by ikegami
in thread Which Date Module?
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |