in reply to Expanding dates

Overkill, but........in the event that this is homework ;-), I'll let you figure out what's going on.
$HelpMessage = " <date/range/week> = YYYYMMDD = individual day YYYYMMDD.YYYYMMDD = series of individual days YYYYMMDD-YYYYMMDD = weeklong reporting period -YYYYMMDD = weeklong reporting period "; ################################################################ if (index($PERIODIN,"-") == 0) { $periodlength = "day"; } else { $periodlength = "week"; } if (!defined $InFileDir) { if ($R_OR_I ne "a" && $R_OR_I ne "b") { if (!(defined $Special)) { $rori = $R_OR_I; } else { $rori = $R_OR_I . "s"; } } elsif ($R_OR_I eq "a") { if (defined $AggrExceptions) { $rori = "ae"; } elsif (defined $Config || defined $Report) { $rori = "ap"; } else { $rori = "ar"; } } elsif ($R_OR_I eq "b") { $rori = "b"; } $InFileDir = $InFileDirX{$rori,$periodlength}; } if (!(-d $InFileDir)) {die "\n Directory $InFileDir \n does not exist\n\n";} $MonthDay[1] = $MonthDays[3] = $MonthDays[5] = $MonthDays[7]=31; $MonthDays[8] = $MonthDays[10] = $MonthDays[12] = 31; $MonthDays[4] = $MonthDays[6] = $MonthDays[9] = $MonthDays[11]=30; $MonthDays[2] = 28; $Leap{1996} = $FakeEndFeb{19960228} = 1; $Leap{2000} = $FakeEndFeb{20000228} = 1; $Leap{2004} = $FakeEndFeb{20040228} = 1; $Leap{2008} = $FakeEndFeb{20080228} = 1; $Leap{2012} = $FakeEndFeb{20120228} = 1; if (index($PERIODIN,".") == 0) { $numdates = 1; if (substr($PERIODIN,1,1) eq "-") { $begdate = $enddate = substr($PERIODIN,2); for (1..6) { $begdate = &getprevday($begdate); } $date[1] = $begdate . "-" . $enddate; } else { $date[1] = $PERIODIN; } } else { ($begdate, $enddate, @junkjunk) = split(/\./,$PERIODIN); $numdates = 1; $date[1] = $perd = $begdate; while ($perd < $enddate) { $numdates++; $date[$numdates] = $perd = &getnextday($perd); } } sub getnextday { local($today) = @_; local($nextday); $nyr = int($today / 10000); $nmo = int(($today - (10000 * $nyr)) / 100); $nda = $today - (10000 * $nyr) - (100 * $nmo) + 1; if (($nmo != 2 && $nda > $MonthDays[$nmo]) || ($nmo == 2 && (!(defined $Leap{$nyr})) && $nda > 28) || ($nmo == 2 && (defined $Leap{$nyr}) && $nda > 29)) { $nda = 1; $nmo = $nmo + 1; if ($nmo > 12) { $nmo = 1; $nyr = $nyr + 1 } } $nextday = $nyr * 10000 + $nmo * 100 + $nda; } sub getprevday { local($today) = @_; local($prevday); $pyr = int($today / 10000); $pmo = int(($today - (10000 * $pyr)) / 100); $pda = $today - (10000 * $pyr) - (100 * $pmo) - 1; if ($pda == 0) { $pmo = $pmo - 1; if ($pmo == 0) { $pyr = $pyr - 1; $pmo = 12; } if ($pmo != 2) {$pda = $MonthDays[$pmo];} elsif (defined $Leap{$pyr}) {$pda = 29;} else {$pda = 28;} } $prevday = $pyr * 10000 + $pmo * 100 + $pda; }