Chapter 4 — The Google Web API 61
Listing 4-1:Simple Perl Example
#!/usr/bin/perl
use SOAP::Lite;
my $key=’*****’;
my $googleSearch = SOAP::Lite->service(“file:GoogleSearch.wsdl”);
my $result = $googleSearch->doGoogleSearch($key,
‘MCslp’,
0,
10,
“false”,
“”,
“false”,
“”,
“latin1”,
“latin1”);
print <<EOF;
Query: $result->{searchQuery}
Showing results $result->{startIndex} to $result-
{endIndex} of $result->{estimatedTotalResultsCount}<br
/>
Search time: $result->{searchTime}
EOF
foreach my $item (@{$result->{resultElements}})
{
$item->{title} = reformat($item->{title});
$item->{snippet} = reformat($item->{snippet});
print <<EOF;
{URL}”>$item->{title}
$item->{snippet}
EOF
}
sub reformat
{
my ($text) = @_;
$text =~ s/</</g;
$text =~ s/>/>/g;
return $text;
}