berm has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have some scripts on the web which use MyParser. They have been working perfectly up until 3 days ago. I have contacted my host but have had little explanation so far. Here is a test URL which contains the following script. http://www.berm.co.nz/cgi-bin/test.cgi?NZXX0003 Can someone upload this script to their server and show me it works for you? It should print out the title. It uses a Yahoo API.
#!/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=$Celc +iusFahrenheit"; #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"; $titl +e_count++;} #if } #sub #end------------------------------------------------------------------ +---------- sub end { my ($self, $tagname, $origtext) = @_; if ($tagname =~ /^title$/i) {$title_flag = 0;} } #sub package main; my $html = <<EOHTML; $Content EOHTML my $parser = MyParser->new; $parser->parse( $html ); $parser->eof; #end parse------------------------------------------------------------ +---------- #--------------------------------------------------------------------- +---------- #print print <<EOF; <html> <head> <title>$Title</title> </head> <body> $Title </body> </html> EOF exit;

Replies are listed 'Best First'.
Re: MyParser Question
by ikegami (Patriarch) on Jul 26, 2007 at 02:48 UTC

    "Maybe someone deleted the file from your web server" is as good an answer as any other since you didn't tell us how it fails. In fact, you didn't even tell us it's failing! What is does it return to the browser? What does it put in the error log? What was returned by LWP in $response?

    By the way, please add <readmore>...</readmore> around the code in the OP. It's too large.

    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.