#!/usr/bin/perl use strict; use LWP::Simple; use HTML::Parse; use HTML::FormatText; use URI::Escape; my ($word, $dict, $url, $html, $ascii); unless(defined $ARGV[0]){ print "usage: \n"; print "dictionary: lookup.pl | ''\n"; print "thesaurus: lookup.pl -syn | ''\n"; print "word du jour: lookup.pl -wod\n"; print "random word: lookup.pl -rand [list]\n"; exit 1; } if ($ARGV[0] eq "-wod"){ $url = "http://www.dictionary.com/wordoftheday/"; }elsif($ARGV[0] eq "-syn"){ $word = uri_escape($ARGV[1]); $url = "http://www.thesaurus.com/cgi-bin/search?config=roget&words=$word"; }elsif($ARGV[0] eq "-rand"){ if (defined $ARGV[1]){ $dict = $ARGV[1]}else{$dict = "/usr/dict/words"}; open (WORDS, $dict); srand; rand($.) < 1 && ($word = $_) while ; $word = uri_escape($word); $url = "http://www.dictionary.com/cgi-bin/dict.pl?term=$word"; }else{ $word = uri_escape($ARGV[0]); $url = "http://www.dictionary.com/cgi-bin/dict.pl?term=$word"; } print "getting it...\n"; $html = get($url); defined $html or die "Can't lookup $ARGV[0] from dictionary.com\n"; print "got it.\n"; $ascii = HTML::FormatText->new->format(parse_html($html)); print "converted it...\n"; print $ascii; print $url, "\n";