#!/usr/bin/perl

# Which file holds the info?
$filename = ".mycalendar";

# Let's make sure that the file '$filename' exists!
die "$filename doesn't exist\n" if (! -e $filename);

# Let's process the dates....
# do you want to use 'Date' module? Go ahead...
$todays_date = `date`;
chop $todays_date;
@todays_date = split /\s+/, $todays_date;
($tmonth, $tday) = ($todays_date[1], $todays_date[2]);

# Let's check the file.
open (FILENAME, "$filename") || die "error opening file $filename";
print " --- Schedule for $todays_date --- \n";
while ($line = <FILENAME>)
{
   chop $line;

   # Let's skip the comments or blank lines!
   next if ($line =~ /^\s*#/ || $line =~ /^\s*$/);

   # Let's split the lines
   @fields = split /\s+/, $line;

   # Let's grab the appropriate fields
   $len = $#fields + 1;
   ($month, $day, $year) = ($fields[0], $fields[1], $fields[2]);
   @message = @fields[3..($len - 1)];

   # Let's print if there is appropriate message
   if ($day =~ /^$tday$/i && $month =~ /^$tmonth$/i)
   {
      print "@message\n";
   }
}
print "--------------------------------------------------\n";
