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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.