Related/possible duplicate: http://stackoverflow.com/questions/1263943/why-do-i-get-uninitialized-value-warnings-when-i-use-datemanips-sortbylength
This block of code:
my @sorted_models = sort {
UnixDate($a->{'year'}, "%o") <=>
UnixDate($b->{'year'}, "%o")
} values %{$args{car_models}};
kept generating the following error warning:
Use of uninitialized value in length at /.../Date/Manip.pm line 244.
Date::Manip is a CPAN module. And line 244 of Date::Manip is found within the following block of code:
# Get rid of a problem with old versions of perl
no strict "vars";
# This sorts from longest to shortest element
sub sortByLength {
return (length $b <=> length $a);
}
use strict "vars";
But then including this (printing out the actual Unix Date value to the console in the logger) before the block of code to sort the values:
foreach (values %{$args{car_models}}) {
$g_logger->info(UnixDate($_->{'year'},"%o"));
}
removed the errors warnings entirely. Why? And what is a good fix instead of doing all these logging statements?
NOTE: None of the sorted values are undefined because when I printed them out in the logger, I could see that every one of them had a numerical value.