I think it's cool to have a command line dictionary at my disposal, so
I installed the Net::Dict perl module via the CPAN shell:
#> perl -MCPAN -e 'shell'
CPAN> install Net::Dict
And adapted the simple.pl example that comes with that module, named
it webster, set it executable in my bin. Now if I type
'webster linux', I get a definition almost instantly.
Here's the perl source...
#!/usr/bin/perl -w
#
# Pass in a word from the command line
#
use strict;
use Net::Dict;
my $word = $ARGV[0] if ($ARGV[0] ne '') || die "Need a word to lookup\n";
my ($dict, $eref, $entry, $db, $definition);
# Turn off buffering on STDOUT
#-----------------------------------------------------------------------
$| = 1;
# Create instance of Net::Dict, connecting to dict.org
#-----------------------------------------------------------------------
print "Looking up '$word' at dict.org ...";
$dict = Net::Dict->new("dict.org");
print "\n";
# The define() method returns an array reference.
# The array has one entry for each definition found.
# If the referenced array has no entries, then there were no
# definitions in any of the dictionaries on the server.
#-------------------------------------------------------------------
$eref = $dict->define($word);
if (@$eref == 0) {
print " no definition for '$word'\n";
} else {
# Each entry is another array reference. The referenced array
# for each entry has two elements:
# $db - the name of the database (ie dictionary)
# $definition - the text of the definition
#---------------------------------------------------------------
foreach $entry (@$eref) {
($db, $definition) = @$entry;
print "\nFrom: $db" ,
"\n-------------------------------------------\n",
$definition;
}
}
1;
That's it!
-Rob
:: 5 out of 4 people have trouble with fractions. ::