ecuguru has asked for the wisdom of the Perl Monks concerning the following question:
This is my entire perl source code. Anyone see anything obvious that I'm doing wrong? I've noticed that when I set the number of responses (xml responses) to 1, the code works. It's when there are multiple entries that it freaks out with this error.Pseudo-hashes are deprecated at WebYahooSites2.pl line 28. Argument "\x{42}\x{72}..." isn't numeric in hash element at WebYahooSi +tes2.pl line 28. Bad index while coercing array into hash at WebYahooSites2.pl line 28.
#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $resp; ##Holds the content my $appID = "YahooDemo"; my $resultsNum = "5"; my $site = 'http://api.search.yahoo.com/WebSearchService/V1/webSearch? appid=YahooDemo&query=Spears&results='.$resultsNum.'&format=html'; my $response = $ua->get($site); if ($response->is_success) { $resp = $response->content; # or whatever } else { my $err = $response->status_line; print "Error: $err \n"; } use XML::Simple; my $xml = new XML::Simple; my $doc = $xml->XMLin($resp); my $recordNum = 0; for( ref $doc->{Result} eq "HASH"?$doc->{Result}:ref $doc->{Result}eq +"ARRAY"?@{$doc- >{Result}}:() ){ print "Title: $doc->{Result}{Title}\n"; print "Url: $doc->{Result}{Url}\n"; print "MimeType: $doc->{Result}{MimeType}\n"; print "Cache URL: $doc->{Result}{Cache}{Url}\n"; $recordNum++; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing Yahoo XML Response
by GrandFather (Saint) on Jan 06, 2007 at 09:20 UTC | |
by ecuguru (Monk) on Jan 06, 2007 at 10:07 UTC | |
by ecuguru (Monk) on Jan 06, 2007 at 09:48 UTC | |
by GrandFather (Saint) on Jan 06, 2007 at 10:09 UTC | |
by ecuguru (Monk) on Jan 06, 2007 at 10:15 UTC | |
|
Re: Parsing Yahoo XML Response
by merlyn (Sage) on Jan 06, 2007 at 11:17 UTC | |
by ecuguru (Monk) on Jan 06, 2007 at 19:45 UTC | |
|
Re: Parsing Yahoo XML Response
by Anonymous Monk on Jan 06, 2007 at 09:08 UTC |