in reply to Something simpler than HTML::Calendar::Simple


Here is something even simpler. Possibly too simple:
#!/usr/bin/perl -wl use strict; # Get the month using cal my @cal = `cal @ARGV`; my $date = shift @cal; $date =~ s/^\s+//; $date =~ s/\s+$//; shift @cal; # Ignore short day names pop @cal; # Ignore blank row unshift @cal, 'Sun Mon Tue Wed Thu Fri Sat'; # Add days # Some simple Html formatting print '<html>'; print '<head>'; print '<center>'; print '<table border="1">'; print "\t<tr>\n\t\t<td colspan=\"7\">" . "<center>$date</center></td>\t\n</tr>"; # Print each day as a <td> element for (@cal) { print "\t<tr>"; my @days = split ' '; # Left or right pad short weeks if (@days < 7) { if ($days[0] == 1) { unshift @days, ('&nbsp;') x (7 -@days); } else { push @days, ('&nbsp;') x (7 -@days); } } print "\t\t<td>$_</td>" for @days; print "\t</tr>"; } print '</table>'; print '</center>'; print '</head>'; print '</html>'; __END__

It uses the Unix cal utility to generate the months and it takes month and year as optional arguments. Here is some sample output, add formatting to taste:

    perl html_cal.pl

June 2003
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

    perl html_cal.pl 5 2003

May 2003
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

--
John.