How Perl Saved my DayExample 3 |
The solution
#!/usr/local/bin/perl # home of Perl
require WWW::Search; # use someone else's
# solution of the hard bit
$search = new # generate a new
WWW::Search('AltaVista::AdvancedWeb'); # search object
$query = "heavy near metal near transport"; # that's what we look for
$max = $search->maximum_to_retrieve(1000); # max nr of results
$search->timeout(240); # timeout in seconds
$search->native_query(WWW::Search::escape_query($query)); # set the query
%results = (); # initialize a hash[Note 5]
# that will hold the results
while ($result = $search->next_result()) { # retrieve results
$url = $result->url(); # store url,
$title = $result->title(); # title, and
$description = $result->description(); # description
$title =~ s/\t/ /g; # remove tabs from title
$description =~ s/\t/ /g; # and description
$results{$url} = # store the result in
"<LI><A HREF=$url>$url</A>\n" . # the hash, using the URL as
"<B>$title</B><BR>\n" . # key and the rest as value,
$description . "\n"; # with HTML formatting
}
print "<OL TYPE=1>\n<SMALL>"; # print to standard output
foreach $key (sort keys %results) { # sorted by URL's
print $results{$key};
}
print "</OL></SMALL>\n";
|
|
10.12.1998 Michael Gfeller |