我编写了一些 perl 代码,用于从 NOAA 获取天气数据/警报。
我的代码很简单:
use Weather::NOAA::Alert;
use Data::Dumper;
$alert = Weather::NOAA::Alert->new(['TXC301']);
$events = $alert->get_events();
$alert->poll_events();
print Dumper($events);
# @url = (keys %{$VAR1->{'TXC301'}});
# $url = $VAR1->{'TXC301'};
$url = $events->{'TXC301'};
print "URL is $url\n";
# $expires= $events->{'TXC301'}->{$url}->{'expires'};
$expires= $events->{'TXC301'}->{'http://alerts.weather.gov/cap/wwacapget.php?x=TX12516CBE9400.FloodWarning.12516CC068C0TX.MAFFLWMAF.f21e7ce7cf8e930ab73a110c4d912576'}->{'expires'};
print "Expires: $expires\n";
输出:
$VAR1 = {
'TXC301' => {
'http://alerts.weather.gov/cap/wwacapget.php?x=TX12516CBE9400.FloodWarning.12516CC068C0TX.MAFFLWMAF.f21e7ce7cf8e930ab73a110c4d912576' => {
'certainty' => 'Likely',
'senderName' => 'NWS Midland-Odessa (Western Texas and Southeastern New Mexico)',
'urgency' => 'Expected',
'instruction' => 'A FLOOD WARNING MEANS THAT FLOODING IS IMMINENT OR HAS BEEN REPORTED.
STREAM RISES WILL BE SLOW AND FLASH FLOODING IS NOT EXPECTED.
HOWEVER... ALL INTERESTED PARTIES SHOULD TAKE NECESSARY PRECAUTIONS
IMMEDIATELY.
DO NOT DRIVE YOUR VEHICLE INTO AREAS WHERE THE WATER COVERS THE
ROADWAY. THE WATER DEPTH MAY BE TOO GREAT TO ALLOW YOUR CAR TO CROSS
SAFELY.',
'description' => 'THE NATIONAL WEATHER SERVICE IN MIDLAND HAS ISSUED A
FLOOD WARNING FOR...
SOUTHWESTERN LOVING COUNTY IN WEST TEXAS...
NORTHWESTERN WARD COUNTY IN WEST TEXAS...
NORTH CENTRAL REEVES COUNTY IN SOUTHWEST TEXAS...
UNTIL 300 PM CDT FRIDAY
AT 259 AM CDT...ROADS REMAIN CLOSED NEAR THE PECOS RIVER BETWEEN
RED BLUFF AND INTERSTATE 20 BECAUSE OF ELEVATED RIVER LEVELS DUE
TO RECENT RAINS. FLOODING WILL ALSO IMPACT THE CITY OF PECOS.',
'event' => 'Flood Warning',
'delete' => 0,
'category' => 'Met',
'severity' => 'Moderate',
'effective' => '2014-09-26T03:00:00-05:00',
'headline' => 'Flood Warning issued September 26 at 3:00AM CDT until September 26 at 3:00PM CDT by NWS Midland-Odessa',
'expires' => '2014-09-26T15:00:00-05:00'
}
}
};
URL is HASH(0x26384c0)
Expires: 2014-09-26T15:00:00-05:00
TXC301 是一个报告标识符。
脚本的输出将打印从 NOAA 获取的所有值。
目标是存储/返回“过期”值。
我已经注释掉了几行,这是为了实现我的目标的尝试。
我遇到的问题是获取 $url 变量。我需要这个值才能获得我的 $expires 值。我的代码中倒数第二行将正确获取 $expires 值,但为了做到这一点,我需要将 URL 硬编码到该行中。
我正在尝试使该线(倒数第三个)正上方的线起作用:
$expires= $events->{'TXC301'}->{$url}->{'expires'};
但这取决于要存储的 $url 值。我似乎无法弄清楚如何获取 $url 值。
我的猜测:
@url = (keys %{$VAR1->{'TXC301'}});
$url = $VAR1->{'TXC301'};
$url = $events->{'TXC301'};
这些都不起作用。
任何帮助都会很棒。
谢谢!
问候,
约瑟夫·斯宾纳