#!/usr/bin/perl use strict; use Geo::WeatherNOAA; use CGI qw(param); my ($city, $state); if (param("city")) { $city = param("city"); } else { $city = "Minneapolis"; } if (param("state")) { $state = param("state"); } else { $state = "MN"; } print "Content-type: text/html\n\n"; print < NOAA Weather

Perl Weather Reporter


EOHTML print "
\n"; print "\n"; print "\n"; print "
City:
State: "; print_state_select_menu(); print "
\n"; print "

Weather Forecast for $city, $state

"; my $html_weather_table = get_weather_data($city,$state); print $html_weather_table; print "\n"; exit; sub get_weather_data { my ($city, $state) = @_; my $filename = "weather_cache/${city}_${state}.out"; my ($return, $time, $mtime, $diff); if (-e $filename) { $time = time; $mtime = (stat("weather_cache/$filename"))[9]; $diff = $mtime - $time; } else { $diff = 0; } if ($diff > 3600 || !$diff) { # file older than an hour or doesn't exist $return = make_noaa_table($city,$state); open(CACHE,">$filename") or warn "couldn't open weather_cache/$filename: $!"; print CACHE $return; close(CACHE); return $return; } else { open(CACHE,"<$filename") or warn "couldn't open weather_cache/$filename: $!"; { local $/ = "\0"; $return = ; } close(CACHE); return $return; } } sub print_state_select_menu { print ''; }