The Code
Save the following code to a text file called
google_dir.pl:
#!/usr/bin/perl
# google_dir.pl
# Uses ODP category information to build URLs into the Google Directory.
# Usage: perl google_dir.pl "keywords" < structure.rdf.u8
use strict;
use LWP::Simple;
# Turn off output buffering.
$|++;
my $directory_url = "http://directory.google.com";
@ARGV == 1
or die qq{usage: perl google_dir.pl "{query}" < structure.rdf.u8\n};
# Grab those command-line specified keywords and build a regular expression.
my $keywords = shift @ARGV;
$keywords =~ s!\s+!\|!g;
# A place to store topics.
my %topics;
# Loop through the DMOZ category file, printing matching results.
while (<>) {
/"(Top\/.*$keywords.*)"/i and !$topics{$1}++
and print "$directory_url/$1\n";
}