today.pl -- print this month's calendar with today highlighted


today.pl is a perl program which works with VT100-compatible terminal emulation and prints a small calendar with the current date highlighted.

It requires a Unix-compatible 'cal' command.

Example output:

 
screenshot of calendar with today's date highlighted

Source Code


#!/usr/bin/perl -w
#
# today - print a calendar with today in reverse video (vt100 hardcoded)
# (Handy for a login script). Requires the Unix 'cal' program.
#
#                               April 1999                               
#                             S  M Tu  W Th  F  S                        
#                                         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                           
#                                                                        
#                          Current time is:  7:02 PM

use strict;

use vars qw($min $hour $mday $mon $year $cal $cur $ampm $SO $SE $len );

$SO = "\033[7m";
$SE = "\033[m";
$cal = '/usr/bin/cal';

($min,$hour,$mday,$mon,$year) = (localtime)[1,2,3,4,5];
$mon++; $year+=1900;

open ( CURRENT, "$cal $mon $year |" );

print "\n";
until (eof(CURRENT)) {
    chop($cur = ); 
    next if ($cur eq '');
    $len = 22; 
    $cur =~ s/\b$mday\b/$SO$mday$SE/;
    printf (sprintf("                            %%-20s  %%-%ds\n", $len), $cur );
}
$ampm=($hour>=12) ? "PM" : "AM";
$hour=($hour>=12 ? $hour-12 : $hour);
printf("\n                          Current time is: %2d:%02d %s\n\n",$hour,$min,$ampm);


Back to Kent's Perl Page