|
|
|
Faster and more flexible with perl
The 3 column version looks great, but seems to have to run a lot of stuff. Try this one, all perl -- runs about twice as fast:
#! /usr/bin/perl -w
# multi-column calendar
# setup
$nm = 3; # number of months to output
$ns = 2; # number of spaces between months
################################################################################
#initialize
$fw = $ns + 20; # month field width
@c = (); # $c[month index][line]
(undef,undef,undef,$mday,$mon,$year) = localtime;
$mday+=0;
$mon++;
$year+=1900;
$tm = $mon; # this month
$ty = $year; # and year
# count back
$i = int(($nm - 1) / 2);
while ($i--) {
if (--$tm==0) { $tm = 12; $ty--; }
}
# get calendars
foreach $i (1..$nm) {
$_ = `cal $tm $ty`;
s/^|$/ /gm;
if ($tm == $mon) { s/ ( ?$mday) /[$1]/ }
push @c, [ split /n/ ];
if (++$tm==13) { $tm = 1; $ty++; }
}
# print calendars
foreach $l (0..7) {
foreach (0..$nm-1) {
printf "%-${fw}s", $c[$_][$l] || "";
}
print "n";
}
exit(0);
|
SearchFrom our Sponsor...Latest Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2013 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Powered by Geeklog Created this page in 0.09 seconds |
|