#$/usr/bin/perl -w use strict; use warnings; my ($date, $month, $year, $weekday) = (localtime)[3,4,5,6]; $month++; # Converts $month to human readable. my $days = MonthDays($month, $year); # Figures out how many $days are in current month. my $offset = ($date % 7); # Returns the offset of weekdays today is from the 1st, 0-6. # i.e. 0 means that today's $weekday == the 1st's $weekday. my @months = qw(January February March April May June July August September October November December); my $i = 1; # Set increment counter to 1. $month--; # Converted $month back to machine-readable. $month = $months[$month]; # Converts $month number to month Name $year = $year + 1900; # Converts $year to human readable $weekday = ($weekday - $offset); my @weekdays = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday); ################################################################################################# # # # This section names the file - either journal.txt or journal_month_year.txt # # # # # ################################################################################################# my $file = "journal.txt"; if (-e "journal.txt") { # Checks to see if journal.txt exists. $file = ("journal_" . $month . "_" . $year . ".txt"); # If so, gives it a dated name instead. } if (-e $file) { die "File $file already exists!\n"; sleep(2); # I sleep here so I can read the msg in Win32. } ################################################################################################# # # # OK, now're we're ready to get on with things. This part actually outputs # # the file in a simple, nicely formatted monthly journal. # # # ################################################################################################# open (OUTPUT, "> $file") or die "Could not open file for writing: $!\n"; while ($i <= $days) { print OUTPUT "$weekdays[$weekday], $month $i, $year\n\n\n"; $i++; push(@weekdays, shift(@weekdays)); } close (OUTPUT); sub MonthDays { # This subroutine determines the natural weekday names. my @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 ); my $month = shift(@_); my $year= @_ ? shift(@_) : 1900+(localtime())[5]; if( $year <= 1752 ) { # Note: Although September 1752 only had 19 days, # they were numbered 1,2,14..30! return 19 if 1752 == $year && 9 == $month; return 29 if 2 == $month && 0 == $year % 4; } else { return 29 if 2 == $month and 0 == $year%4 && 0 == $year%100 || 0 == $year%400; } return $monthDays[$month-1]; }