in reply to Producing Calender

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'