#!/usr/bin/perl -w use strict; my @months = qw( January February March April May June July August September October November December ); my ($day, $mon, $year, $dow) = (localtime)[3..6]; my $start_dow = ($dow - ($day - 1)) % 7; for (1 .. shift || 1) { $year++ if $mon != ($mon % 12); $mon %= 12; my $dim = days_in_month($mon,$year); print $months[$mon], ' ', $year + 1900, "\n"; print "Sun Mon Tue Wed Thu Fri Sat\n"; for (1 .. $dim + $start_dow) { print ' ' and next if ($_-1) < $start_dow; printf '%3d', $_ - $start_dow; print $_ % 7 ? ' ' : "\n"; } print "\n" x (($dim + $start_dow) % 7 ? 2 : 1); $start_dow = ($start_dow + $dim) % 7; $mon++; } BEGIN { my @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); sub days_in_month { my ($m,$y) = @_; my $days = $days[$m]; $y += 1900; $days++ if $m == 1 and $y % 4 == 0 and ($y % 100 != 0 or $y % 400 +== 0); return $days; } }

In reply to pcal by japhy

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.