#!/usr/bin/perl print "Content-type: text/html\n\n"; #vars $LocationID = $ENV{QUERY_STRING}; $CelciusFahrenheit = "c"; if ($LocationID =~ ",") { ($LocationID,$CelciusFahrenheit)=split(/\,/,$LocationID); $CelciusFahrenheit = "f"; } #if $url = "http://weather.yahooapis.com/forecastrss?p=$LocationID&u=$CelciusFahrenheit"; #LWP::UserAgent use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->timeout(180); $request = new HTTP::Request('get',"$url"); $request->header('Accept' => 'text/html'); $response = $ua->request($request); $Content = $response->{_content}; #LWP::Simple if response code != 200 and response message ne OK if ($response->{_rc} != 200 && $response->{_msg} ne "OK") { use LWP::Simple; $Content = get("$url"); } #if #parse package MyParser; use base qw(HTML::Parser); #set state flags my $title_flag = 0; my $title_count = 0; #vars set to "" my $Title = ""; #start-------------------------------------------------------------------------- sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; #Title if ($tagname =~ /^title$/i) {$title_flag = 1;} #if } #sub #text--------------------------------------------------------------------------- sub text { my ($self, $text) = @_; #Title if ($title_flag == 1 && $title_count == 0) {$Title = "$text"; $title_count++;} #if } #sub #end---------------------------------------------------------------------------- sub end { my ($self, $tagname, $origtext) = @_; if ($tagname =~ /^title$/i) {$title_flag = 0;} } #sub package main; my $html = <new; $parser->parse( $html ); $parser->eof; #end parse---------------------------------------------------------------------- #------------------------------------------------------------------------------- #print print < $Title $Title EOF exit;