Subject: | Use of uninitialized value in length at /usr/local/share/perl/5.8.4/Weather/Underground.pm line 810. |
I'm using Weather::Underground indirectly on my Movable Type blog via the MT-WeatherUnderground movabletype module that makes variables available from data returned by Weather::Underground. However, if one or both of the windchill variables ends up being null due to the data returned from wunderground.com, I get these annoying warnings:
www-data@void:~/blog/bin$ ./mt-rebuild.pl -mode="index" -blog_id="1" -template="Main Index"
Use of uninitialized value in length at /usr/local/share/perl/5.8.4/Weather/Underground.pm line 810.
Use of uninitialized value in length at /usr/local/share/perl/5.8.4/Weather/Underground.pm line 810.
Use of uninitialized value in length at /usr/local/share/perl/5.8.4/Weather/Underground.pm line 810.
Use of uninitialized value in length at /usr/local/share/perl/5.8.4/Weather/Underground.pm line 810.
I'm not sure if perhaps there has been a change on the wunderground.com site that should result in a change to the regex statements in this block or not, but a fix to suppress the messages is as follows.
To suppress these messages, at line 810 of version 2.20 of Weather/Underground.pm, you can wrap the length() statements that end up working on undefined windchill variables in some cases (at least mine, via movable type weather/underground module) to check first that one of the windchill variables is at least defined. The existing code will then ensure that both are defined after this block.
# fix to suppress warnings "Use of uninitialized value in length..."
if (defined($windchill_celsius) || defined($windchill_fahrenheit)){
if (!length($windchill_celsius) && length($windchill_fahrenheit)) {
$windchill_celsius = ($windchill_fahrenheit - 32) / 1.8;
}
elsif (!length($windchill_fahrenheit) && length($windchill_celsius)) {
$windchill_fahrenheit = ($windchill_celsius * 1.8) + 32;
}
}
Regards,
-J