It just so happens that I have posted some code previously that does just as you ask - It can be found here.

The only module that this code uses is Date::Calc and what it produces is a data structure for the days of the month, sorted into days of the week columns for display via HTML::Template - An example of the HTML template code and a link to example usage is also provided.

 

Update

 

With respect to the desire to perform this calendar function without any additional modules and in light of Ovid's excellent direction above, the Date::Calc methods can be replaced as follows:

sub Day_of_Week { my ( $year, $month, $day ) = @_; if ( $month < 3 ) { $month += 12; --$year; } my $day_of_week = $day + 2 * $month + int( .6 * ( $month + 1) ) + +$year + int( $year / 4 ) - int( $year / 100 ) + int( $year / 400) + 2 +; $day_of_week = int(( $day_of_week / 7 - int( $day_of_week / 7 )) * + 7 + .5); return $day_of_week; } # From Ovid's post at node 139108 (with some modifications) # sub Days_in_Month { my ( $year, $month ) = @_; my @days_in_month = qw/ 31 28 31 30 31 30 31 31 30 31 30 31 /; if ( --$month == 1 ) { return 29 if leap_year( $year ); } return $days_in_month[ $month ]; } sub leap_year { my $year = shift; return ( 0 == $year % 4 and 0 != $year % 100 or 0 == $year % 400 ) + ? 1 : 0; }

These subroutines implement the similarly named methods from the Date::Calc module and allow the use of the code here without the Date::Calc module. Note that I have made a couple of small changes to Ovid's code from (Ovid) Re: Producing Calender so that the subroutine behaviour falls in line with that of the modules from Date::Calc.

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'


In reply to Re: Producing Calender by rob_au
in thread Producing Calender by JBUK

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.