pip has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); open(W, "weather.js"); @lines = <W>; close(W); $out = join('', @lines); if (scalar(@lines) < 3 or -M "weather.js" > 0.25) { use LWP::UserAgent; $ua = LWP::UserAgent->new(); $ua->timeout(60); $request = HTTP::Request->new('GET', 'http://www.bom.gov.au/cgi-bin/wr +ap_fwo.pl?IDS10034.txt'); $res = $ua->request($request); if ($res->is_error) { $str = $res->message; } else { $str = $res->content; } $str =~ s/^.*IDS1003401//s; $str =~ s/HEADLINE.*?$//s; if ($str =~ /:\s+(.*?)\n\n/s) { $adeldesc = $1; $adeldesc =~ s/\n//g; } if ($str =~ /Adelaide City\s+(.*?)\s+Max\s+(\d+)/s) { $adelmax = $2; } if ($str =~ /Noarlunga\s+(.*?)\s+Max\s+(\d+)/s) { $norlmax = $2; } $out =<<EOF; var adeldesc = "$adeldesc"; var adelmax = "$adelmax"; var norlmax = "$norlmax"; EOF open(W, ">weather.js"); print W $out; close(W); } print <<EOF; Content-Type: text/x-javascript Pragma: no-cache Cache-Control: no-cache Expires: -1 $out EOF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: weather without UserAgent.pm ?
by samtregar (Abbot) on Feb 10, 2004 at 23:34 UTC | |
by Anonymous Monk on Feb 12, 2004 at 02:52 UTC | |
by samtregar (Abbot) on Feb 12, 2004 at 05:51 UTC | |
by pip (Novice) on Feb 13, 2004 at 00:00 UTC | |
|
Re: weather without UserAgent.pm ?
by Abigail-II (Bishop) on Feb 10, 2004 at 23:42 UTC | |
by Anonymous Monk on Feb 12, 2004 at 03:02 UTC | |
by Abigail-II (Bishop) on Feb 12, 2004 at 09:12 UTC | |
by Anonymous Monk on Feb 12, 2004 at 23:24 UTC | |
by Abigail-II (Bishop) on Feb 13, 2004 at 00:01 UTC | |
|
Re: weather without UserAgent.pm ?
by scottj (Monk) on Feb 11, 2004 at 00:01 UTC | |
by Anonymous Monk on Feb 12, 2004 at 02:58 UTC |