#!/usr/bin/perl ############################################## ####### ii.pl ######################### ############################################## # This program lists all dates from 01/01/1896 # to 12/31/2009. # The list will be used to submit each date on # the wx station site in order to gather # the required data. ############################################## # COMMENTS COME AFTER THE LINE OF INTEREST use strict; # to ensure scoping obedience use warnings; # provides warnings when syntax is off use diagnostics; # helps use Number::Ops qw(:all); # for using 'isint()' operator when determining leap years my (@nonleaps, @leaps, @dates); # arrays to hold non leap years, leap years, and then all dates my @yrs = (1896 .. 2009); # all years in the period of record (POR) my @mos = ('01', '02', '03', '04', '05', '06', '07', '08', '09', 10, 11, 12); # literal strings must be used for months 1 through 9 because # the web form requires input of 8 characters only (YYYYMMDD) my @feb = ('01', '02', '03', '04', '05', '06', '07', '08', '09', 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28); # days in the month of feb on non leap years. Literal strings # used for the first 9 days for the same reason as above. my @leap = ('01', '02', '03', '04', '05', '06', '07', '08', '09', 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29); # feb days during leap years my @thirty = ('01', '02', '03', '04', '05', '06', '07', '08', '09', 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30); # for those months with 30 days my @thirtyone = ('01', '02', '03', '04', '05', '06', '07', '08', '09', 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); # for those with 31 days #BEGIN FLOW CONTROL# #################### foreach my $yrs (@yrs) {# for each year foreach my $mos (@mos) {# for each month in each year if (isint($yrs/4) && $yrs != 1900) {# if it's a leap year if ($mos=='02') {# if it's feb in a leap year foreach my $leap (@leap) {# then add each day in feb to the date below my $date = "$yrs$mos$leap";# date is YYYYMMDD push (@dates, "$date\n"); # add the date to the array } } elsif ($mos=='04' || $mos=='06' || $mos=='09' || $mos==11) {# if it's april, june, sept, or nov foreach my $thirty (@thirty) {# add thirty days to each month my $date = "$yrs$mos$thirty";# date is YYYYMMDD push (@dates, "$date\n"); # add the date to the array } } else {# if its any of the other months foreach my $thirtyone (@thirtyone) {# add 31 days my $date = "$yrs$mos$thirtyone"; push (@dates, "$date\n"); } } } else {# if it's not a leap year..(do the same, but 28 days in feb)... if ($mos=='02') { foreach my $feb (@feb) { my $date = "$yrs$mos$feb"; push (@dates, "$date\n"); } } elsif ($mos=='04' || $mos=='06' || $mos=='09' || $mos==11) { foreach my $thirty (@thirty) { my $date = "$yrs$mos$thirty"; push (@dates, "$date\n"); } } else { foreach my $thirtyone (@thirtyone) { my $date = "$yrs$mos$thirtyone"; push (@dates, "$date\n"); } } } } } print @dates; open (FH, ">dates.txt");# open a new file for output print FH @dates;# print the array of all dates to the file