in reply to weather script not working
If the version of LWP::UserAgent that was installed does something differently then the version of UserAgent you originally used, the answer is, yes, it could have broken something. However, I've noticed you don't have:
use strict; use warnings;
At the top of your script. So I ran your script and added those two lines and got the following:
Global symbol "@lines" requires explicit package name at - l +ine 8. Global symbol "$out" requires explicit package name at - lin +e 10. Global symbol "@lines" requires explicit package name at - l +ine 10. Global symbol "@lines" requires explicit package name at - l +ine 12. BEGIN not safe after errors--compilation aborted at - line 13. [Fri Feb 13 01:48:06 2004] -: Global symbol "@lines" requires explicit + package name at - line 8. [Fri Feb 13 01:48:06 2004] -: Global symbol "$out" requires explicit p +ackage name at - line 10. [Fri Feb 13 01:48:06 2004] -: Global symbol "@lines" requires explicit + package name at - line 10. [Fri Feb 13 01:48:06 2004] -: Global symbol "@lines" requires explicit + package name at - line 12. [Fri Feb 13 01:48:06 2004] -: BEGIN not safe after errors--compilation + aborted at - line 13.
Now all those errors mean that you're not declaring before using, or that you're not explicitely accessing (i.e. Package::sub instead of sub), and this isn't necessarily the source of your errors. But it's very good practice to use warnings; use strict; at the top of your code because it helps unmask errors.
I would recommend taking the time to go through your script to make it compatible with use strict; use warnings; That may help isolate the problem.
Update: I was thinking about it, and you can compact the following lines of code:
$request = HTTP::Request->new('GET', 'http://www.bom.gov.au/cgi-bin/wr +ap_fwo.pl?IDS10034.txt'); $res = $ua->request($request);
Into:
my $request = $user_agent->get('http://www.bom.gov.au/cgi-bin/wrap_fwo +.pl?IDS10034.txt');
And not to nit pick, but you should always double check your content type. Otherwise you might accidently get a JPEG or something, i.e.:
if ($res->is_error) { $str = $res->message; } else { $str = $res->content; }
Under my example would become:
if ($response->is_success and ($response->content_type eq 'text/html')) { $str = $response->content; } else { $str = "Content type was $response->content_type" unless ($response->content_type eq 'text/html'); $str = $response->status_line unless ($response->is_success); }
Of course, the updates were stylistic and a matter of preference (except for checking content type unless you are absolutely sure you can only get the proper content type). TMTOWTDI
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: weather script not working
by Anonymous Monk on Feb 14, 2004 at 10:41 UTC |