blackjudas has asked for the wisdom of the Perl Monks concerning the following question:
This code uses Date::Calc and the $beginning_date and $ending_date are in the form: 20030218 (year, month, day).my $counter = 0; my %user_ranges = (); my $julian_day = 0; for my $date ($beginning_date..$ending_date) { # run through the main +range and create smaller ranges my ($year, $month, $day) = ((substr $date, 0, 4),(substr $date, 4, 2 +),(substr $date, 6, 2)); next if !check_date ($year, $month, $day); # next iteration if date + is not valid print "passed as a vaild day: $year$month$day<br>"; # next iteration if the weekday range is selected and the date is no +t on a weekday next if (((Day_of_Week ($year, $month, $day)) > 5) && ($session_vars +{'date_type'} == 2)); print "passed as a weekday: $year$month$day<br>" if ($session_vars{'da +te_type'} == 2); # next iteration if the weekend range is selected and the date is no +t on a weekend next if (((Day_of_Week ($year, $month, $day)) < 6) && ($session_vars +{'date_type'} == 3)); print "passed as a weekend: $year$month$day<br>" if ($session_vars{'da +te_type'} == 3); if (($julian_day + 1) == (Day_of_Year ($year, $month, $day))) { #one day later $user_ranges{$counter}->[1] = $date; print "assigned $date as end date to range # $counter<br>"; $julian_day++; print "same range: julian day-$julian_day -- counter-$counter -- d +ate: $date<br>"; } else { # this is where the problem lies, notice '$counter >= 1' used to read +!$counter if ((!$user_ranges{$counter}->[1]) && ($counter >= 1)) { # if rang +e is one day long print "\n\ncounter: $counter -- user ranges 0: $user_ranges{$counter}- +>[0] -- user ranges 1: $user_ranges{$counter}->[1]<br>"; $user_ranges{$counter}->[1] = $user_ranges{$counter}->[0]; } #range switch $counter++; $user_ranges{$counter}->[0] = $date; print "assigned $date as beginning date to range # $counter<br>"; $julian_day = Day_of_Year ($year, $month, $day); print "new range: julian day-$julian_day -- counter-$counter -- da +te: $date<br>"; } }
20030326 Edit by Corion: Changed (8-space) tabs to 2 spaces
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Imaginary Key
by Enlil (Parson) on Mar 25, 2003 at 03:14 UTC | |
by blackjudas (Pilgrim) on Mar 25, 2003 at 18:42 UTC |