Subject: | Removing uninitialized value warnings in Date constraints |
Although 3.58 cleared up many related warnings, there were two still left that I was running into:
Use of uninitialized value in string eq at /usr/share/perl5/Data/FormValidator/Constraints/Dates.pm line 94
Use of uninitialized value in string eq at /usr/share/perl5/Data/FormValidator/Constraints/Dates.pm line 95
I took a very simplistic (and, I believe, obviously correct) approach and came up with the following patch:
--- Dates.pm~ 2004-05-05 19:11:04.000000000 -0500
+++ Dates.pm 2004-05-25 15:41:32.000000000 -0500
@@ -91,8 +91,10 @@
$result{$format->[1]->[$i]} ||= $data[$i];
}
- $result{h} += 12 if ($result{p} eq 'PM' and $result{h} != 12);
- $result{h} = 0 if ($result{p} eq 'AM' and $result{h} == 12);
+ if (exists $result{p}) {
+ $result{h} += 12 if ($result{p} eq 'PM' and $result{h} != 12);
+ $result{h} = 0 if ($result{p} eq 'AM' and $result{h} == 12);
+ }
return $untainted_date, map {defined $result{$_} ? $result{$_} : 0} qw(Y M D h m s);