print "Content-type: text/plain\n\n"; print "A week ago the date was ",date_a_week_ago(),"\n"; # return a date one week ago as a string in format: MM/DD/YYYY sub date_a_week_ago { my @month_len = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my($day, $month, $year) = (localtime)[3..5]; for (my $j = 0; $j < 7; $j++) { $day--; if ($day == 0) { $month--; if ($month == 0) { $year--; $month = 12; } # there are 29 days in February in a leap year $month_len[1] = ($year % 400 == 0 or ($year % 4 == 0 and $year % 100)) ? 29 : 28; # set $day to be the last day of the previous month $day = $month_len[$month - 1]; } } return sprintf "%02d/%02d/%04d", $month, $day, $year+1900; }