I'm in a generous mood today, so here is a re-write of your script that should work a bit better than the original:
#!/usr/bin/perl -w use strict; use HTML::TokeParser; use LWP::UserAgent; my %cities = ( "City" => { var => 'adelmax' }, "Elizabeth" => { var => 'elizmax' }, "Noarlunga" => { var => 'noarmax' }, "Mount Barker" => { var => 'mtbkmax' } ); my $ua = LWP::UserAgent->new(); $ua->timeout(60); my $request = HTTP::Request->new('GET', 'http://www.bom.gov.au/cgi-bin +/wrap_fwo.pl?IDS10034.txt'); my $result = $ua->request($request); my $content = $result->content; my $p = HTML::TokeParser->new(\$content); my @lines; while (my $tag = $p->get_tag("pre")) { my $text = $p->get_text("/pre"); @lines = split /\n/, $text; } my $adeldesc; my $cnt; for my $line (@lines) { if ($line =~ /^Forecast for/ && !$adeldesc) { $adeldesc = $lines[$cnt+1]; } if ($line =~ /^([\w\s]+):\s+Max\s(\d+)/) { $cities{$1}{max} = $2; } $cnt++; } my $out = "var adeldesc = $adeldesc\n"; for (keys %cities) { $out .= qq(var $cities{$_}{var} = "$cities{$_}{max}"\n); } open W, ">", "weather.js" or die "Could not open weather.js for writing:$!\n"; print W $out; close W; print <<EOF; Content-Type: text/x-javascript Pragma: no-cache Cache-Control: no-cache Expires: -1 $out EOF
Output:
Content-Type: text/x-javascript Pragma: no-cache Cache-Control: no-cache Expires: -1 var adeldesc = Fine and cool day with increasing high cloud. Moderate + east to northeast winds. var mtbkmax = "11" var noarmax = "13" var adelmax = "13" var elizmax = "13"

As cwry pointed out, the reason it probably broke in the first place is because our good friends (and my ex-collegues) at the BOM decided to change "Adelaide City" to just "City". However, there were several other bad™ practices exhibited in your code, such as:

Cheers,
Darren :)


In reply to Re: weather fetching script by McDarren
in thread weather fetching script by pip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.