use strict; use warnings; my \$delta = int(shift); my \$delta_years = int(abs(\$delta)/12); my \$delta_months = abs(\$delta) % 12; my \$cur_month = (localtime)[4]; my \$cur_year = (localtime)[5]+1900; if (\$delta < 0) { \$delta_years *= -1; \$delta_months *= -1; } if (\$delta_months < 0) { if (abs(\$delta_months) > \$cur_month) {\$delta_years--;} } else { if (\$delta_months > (12 - \$cur_month)) {\$delta_years++;} } my \$new_month = \$cur_month + \$delta_months; my \$new_year = \$cur_year + \$delta_years; my @days = qw(31 28 31 30 31 30 31 31 30 31 30 31); my @months = qw(January February March April May June July August September October November December); my \$answer = \$days[\$new_month]; if ((\$new_month == 2) && (Is_Leap_Year(\$new_year))) {\$answer = 29;} print "\$months[\$new_month] has \$answer days.\n"; ########### sub Is_Leap_Year { my \$year = shift; if ((\$year % 100) == 0) {return 1;} if ((\$year % 4) == 0) { if ((\$year % 25) == 0) { return 0; } else {return 1;} } else {return 0;} }