Save the following code as a CGI script ["How to Run
the Hacks" in the Preface] named
sinker.cgi in your web site's
cgi-bin directory.
#!/usr/local/bin/perl
# sinker.cgi
# Weight a specific keyword in a Google query.
use strict;
use CGI qw{:standard};
# Display the query form if both a query and sinker are not provided.
unless (param('query') and param('sinker')) {
print
header( ),
start_html("Search Sinker"),
h1("Search Sinker"),
start_form(-method=>'GET'),
'Query: ', textfield(-name=>'query'), p( ),
'Sinker (word to weight): ', textfield(-name=>'sinker'), p( ),
submit(-name=>'submit', -value=>'Search'), p( ),
"You will be taken straight to a Google results page. Be sure to look in the Google
query box at the top of the page to see how your query turned out.",
end_form( ), p( );
}
else {
# Normalize the sinker and prefix with a space.
my($sinker) = param('sinker') =~ /^\s*(.+)\s*$/;
$sinker = " $sinker";
# Build the Google query URL.
my $query = param('query') . $sinker x ( 10 - (scalar split / /, param('query')) );
# Webify the query.
$query =~ s/([^a-zA-Z0-9 ])/"%".sprintf("%2.2x", unpack("C", ($1)))/eg;
$query =~ tr/ /+/;
# Redirect the browser to Google, sinker search in tow
print redirect("http://www.google.com/search?num=100&q=$query");
}