in reply to Re^5: weather fetching script
in thread weather fetching script

Hi Darren, I was just wondering ...when the script outputs its description, only the 1st line of the sentence is displayed, even so the bom txt (sometimes) contains another line. Example: Script output: Fine and cool to mild day with increasing high cloud. Light winds, chiefly BOM txt output: Fine and cool to mild day with increasing high cloud. Light winds, chiefly northeast to northwest. Question: Is it possible to display all of the description, regardles if 1 or 2 sentences, and have 'precis' act as the 'full stop'of the description? cheers, pip

Replies are listed 'Best First'.
Re^7: weather fetching script
by McDarren (Abbot) on Jul 25, 2006 at 03:38 UTC
    This is Perl - easy things are easy, and difficult things are possible ;)

    Okay, this is a fairly dirty hack - but it should do the trick. You need to change the for loop that extracts the information from the @lines array to look like this:

    for my $line (@lines) { if ($line =~ /^Forecast for/ && !$adeldesc) { while ($lines[$cnt++] ne "") { $adeldesc .= " $lines[$cnt]"; } } if ($line =~ /^([\w\s]+):.*?Max\s+(\d+)/) { $cities{$1}{max} = $2; } $cnt++; }

    The change is the insertion of the while loop at the top, which basically says: "If the next line is not blank, append its contents to the $desc variable. (There always appears to be a blank line before the precis forecast).

    This gives me the following output:

    var adeldesc = " Fine, with high cloud. Cool to mild with light to mod +erate northeast to northwest winds. " var mtbkmax = "15" var noarmax = "16" var adelmax = "17" var elizmax = "17"

    Cheers,
    Darren :)

      Thanks Darren, That did the trick ...thanks so much! cheers, pip