#!/usr/bin/perl # # 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 #----------------------------------------------------------------------- $|++; # 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; $definition =~ s/{([A-Za-z0-9_-]*?)}/$1<\/a>/g; print "\n\nFrom: $db" , "\n-------------------------------------------\n", $definition; } } 0;