#!/usr/pkg/bin/perl 

use strict;
use warnings;

use v5.10.0;

use Calendar::Simple;

my @months = qw(January February March April May June July August
                September October November December);

my $month      = shift // (localtime)[4] + 1;
my $year       = shift // (localtime)[5] + 1900;
my $start_date = shift // 1;

$start_date %= 7;

my @month = calendar($month, $year, $start_date);
my $month_name = $months[$month - 1];
my $pad = int((20 - length("$month_name $year")) / 2);
print "\n", ' ' x $pad, "$month_name $year\n";

my @days = qw(Su Mo Tu We Th Fr Sa);
push @days, splice @days, 0, $start_date;
print "@days\n";

foreach (@month) {
  print map { $_ ? sprintf "%2d ", $_ : '   ' } @$_;
  print "\n";
}
