Perl Code for today.pl


As noted on the main today.pl page, this program is not so necessary any longer due to Gnu and BSD cal programs having this feature now. I'm leaving this here as an historical example of what I had to do to make it work when the cal program I had wouldn't do the day highlighting.

#!/usr/bin/env perl
#
# today - print a calendar with today in reverse video (vt100 hardcoded)
# (Handy for a login script)
#
#                               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

our ($min, $hour, $mday, $mon, $year, $current_line, $len);

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

open ( CALENDAR, "/usr/bin/cal $mon $year |" );

print "\n";
until (eof(CALENDAR)) {
    chop($current_line = <CALENDAR>);
    $len = 22;
    $current_line =~ s/\b$mday\b/\033[7m$mday\033[m/;
    printf (sprintf("                            %%-20s  %%-%ds\n", $len), $current_line );
}
printf("\n                          Current time is: %2d:%02d %s\n\n",
        ($hour>12 ? $hour-12 : $hour),$min,($hour>=12 ? "PM" : "AM"));


Back to today.pl Perl Page
Last Modified: Mon Sep 22 16:10:27 EDT 2025