It comes from a lack of error checking. The following unexpectedly returns undef
:
JSON::Any->jsonToObj($json)->{current_observation}
You might want to have a look at what's getting fetched by using the following:
use LWP::Simple qw( get );
my $api_key = 'my key';
my $location = 'KIAD';
print get("http://api.wunderground.com/api/$api_key/conditions/q/$location.json");
Perhaps there's an error message in the response you can address. For example, a bad API key would result in the following response:
{
"response": {
"version": "0.1"
,"termsofService": "http://www.wunderground.com/weather/api/d/terms.html"
,"features": {
}
,
"error": {
"type": "keynotfound"
,"description": "this key does not exist"
}
}
}