#!/local/bin/perl @day_of_week = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); print "Enter \"a\" if you would like to see a specific week\n"; print "Enter \"b\" if you would like to add appointments\n"; $choice = ; chomp $choice; while ($choice ne "c") { if ($choice eq "a") { print "Enter a date in the following format: dd/mm/yy "; $date = ; chomp $date; ($day, $month, $year) = split (/\//, $date); ($this_year, $this_month, $this_day)= find_monday ($year, $month, $day); for ($i = 0 ; $i < 7; $i++) { print "$day_of_week[$i] $this_day/$this_month/$this_year"; foreach $elem (@appts) { if ($elem =~ /^$this_day\/$this_month\/$this_year (.*)/) { print " $1"; last; } } print "\n"; $this_day++; ($this_day, $this_month, $this_year) = end_of_month ($this_day, $this_month, $this_year); } } elsif ($choice eq "b") { print "Enter a date in the following format: dd/mm/yy "; $date = ; chomp $date; $is_this_new = check_for_existing_appt ($date); if ($is_this_new ne "no") { print "Enter new appointment:\n"; $new_appt = ; chomp $new_appt; $elem = "$date $new_appt"; push (@appts, $elem); } } print "Enter \"a\" if you would like to see a specific week\n"; print "Enter \"b\" if you would like to add appointments\n"; print "Enter \"c\" to exit this program\n"; $choice = ; chomp $choice; } ##### end of main program ################################# #### subroutines ########################################## sub end_of_month { ### this subroutine deals with the end of the month/year my $this_month = $this_month; my $this_day = $this_day; my $this_year = $this_year; if (($this_month eq "12") and ($this_day eq "32")) { $this_day = "01"; $this_month = "01"; $this_year = "02"; } elsif (($this_month eq "01") and ($this_day eq "32")) { $this_day = "01"; $this_month = "02"; } elsif (($this_month eq "02") and ($this_day eq "29")) { $this_day = "01"; $this_month = "03"; } elsif (($this_month eq "03") and ($this_day eq "32")) { $this_day = "01"; $this_month = "04"; } elsif (($this_month eq "04") and ($this_day eq "31")) { $this_day = "01"; $this_month = "05"; } return ($this_day, $this_month, $this_year); } ##################################################################### sub find_monday { #### To determine in which week a date belongs, the date is #### compared to the array @mondays. All dates are reversed. #### That facilitates comparing them based on their #### alphabetical ordering. @mondays=("01/12/03", "01/12/10", "01/12/17", "01/12/24", "01/12/31", "02/01/07", "02/01/14", "02/01/21", "02/01/28", "02/02/04", "02/02/11", "02/02/18", "02/02/25", "02/03/04", "02/03/11", "02/03/18", "02/03/25", "02/04/01", "02/04/08", "02/04/15", "02/04/29"); my $day = $day; my $month = $month; my $year = $year; $reverse_date = "$year/$month/$day"; $this_monday = ""; foreach $elem (@mondays) { if ($reverse_date ge $elem) { $this_monday = $elem; } if (($reverse_date lt $elem) and $this_monday) { last; } } ($this_year, $this_month, $this_day) = split (/\//, $this_monday); return ($this_year, $this_month, $this_day); } ############################################################## sub check_for_existing_appt { my $date = $date; $is_this_new = ""; foreach $elem (@appts) { if ($elem =~ /^$date/) { $is_this_new = "no"; print "This date already has an appointment\n"; print "Enter \"d\" to delete the old appointment\n"; print "Enter \"r\" to replace the old appointment\n"; print "Enter \"a\" to add a second appointment\n"; $which = ; chomp $which; if ($which eq "d") { $elem = ""; } elsif ($which eq "r") { print "Enter new appointment:\n"; $new_appt = ; chomp $new_appt; $elem = "$date $new_appt"; } elsif ($which eq "a") { print "Enter new appointment:\n"; $new_appt = ; chomp $new_appt; $elem = "$elem $new_appt"; } } } return $is_this_new; }