#!/usr/local/bin/perl
#
# Use google to figure out how popular each four-letter word in
# /usr/dict/words is
require 'flush.pl';

open (WORDS, 'grep \'^[a-z]...$\' /usr/dict/words|') || die "$!";
while (defined($word = <WORDS>)) {
	chomp $word;
	open (GOOGLE, 'snarf \'http://www.google.com/search?q='.$word.'\' -|') || die "on $word: $!";
	while (defined($line = <GOOGLE>)) {
		if ($line =~ m/Google results.*of about <b>([\d,]+)<\/b>/) {
			print "$word $1\n";
			flush(STDOUT);
			last;
		}
	}
}
