#$/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 weekd +ays today is from the 1st, 0-6. # i.e. 0 means that today's $weekday == th +e 1st's $weekday. my @months = qw(January February March April May June July August Sept +ember October November December); my $i = 1; # Set increment counter to 1. $month--; # Converted $month back to machine-re +adable. $month = $months[$month]; # Converts $month number to m +onth Name $year = $year + 1900; # Converts $year to human rea +dable $weekday = ($weekday - $offset); my @weekdays = qw(Monday Tuesday Wednesday Thursday Friday Saturday Su +nday); ###################################################################### +########################### # # # This section names the file - either journal.txt or journal_m +onth_year.txt # # # # # ###################################################################### +########################### my $file = "journal.txt"; if (-e "journal.txt") { # Checks to see if journal.txt exi +sts. $file = ("journal_" . $month . "_" . $year . ".txt"); # If so, gi +ves 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 W +in32. } ###################################################################### +########################### # # # OK, now're we're ready to get on with things. This part actua +lly 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 natura +l 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]; }

In reply to Plaintext monthly journal generator by Dragonfly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.