0: #!/usr/bin/perl
1: use strict;
2:
3: use LWP::Simple;
4: use HTML::Parse;
5: use HTML::FormatText;
6: use URI::Escape;
7:
8: my ($word, $dict, $url, $html, $ascii);
9: unless(defined $ARGV[0]){
10: print "usage: \n";
11: print "dictionary: lookup.pl <word> | '<phrase>'\n";
12: print "thesaurus: lookup.pl -syn <word> | '<phrase>'\n";
13: print "word du jour: lookup.pl -wod\n";
14: print "random word: lookup.pl -rand [list]\n";
15:
16: exit 1;
17: }
18:
19: if ($ARGV[0] eq "-wod"){
20: $url = "http://www.dictionary.com/wordoftheday/";
21: }elsif($ARGV[0] eq "-syn"){
22: $word = uri_escape($ARGV[1]);
23: $url = "http://www.thesaurus.com/cgi-bin/search?config=roget&words=$word";
24: }elsif($ARGV[0] eq "-rand"){
25: if (defined $ARGV[1]){ $dict = $ARGV[1]}else{$dict = "/usr/dict/words"};
26: open (WORDS, $dict);
27: srand;
28: rand($.) < 1 && ($word = $_) while <WORDS>;
29: $word = uri_escape($word);
30: $url = "http://www.dictionary.com/cgi-bin/dict.pl?term=$word";
31: }else{
32: $word = uri_escape($ARGV[0]);
33: $url = "http://www.dictionary.com/cgi-bin/dict.pl?term=$word";
34: }
35:
36: print "getting it...\n";
37: $html = get($url);
38: defined $html or die "Can't lookup $ARGV[0] from dictionary.com\n";
39: print "got it.\n";
40: $ascii = HTML::FormatText->new->format(parse_html($html));
41: print "converted it...\n";
42: print $ascii;
43: print $url, "\n"; In reply to lookup.pl - a command line dictionary/thesaurus by dshahin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |