Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

dict.org cli lookup

by diotalevi (Canon)
on Dec 11, 2004 at 06:54 UTC ( #414072=sourcecode: print w/replies, xml ) Need Help??
Category: Text Processing
Author/Contact Info
Description: Convenient access to dict.org from emacs, your shell, and if you like, other programs.
Use strict;
use warnings;
use Net::Dict;
use vars qw( $DICT $DICT_HOST %DICT_PARAMS );

$DICT_HOST = 'dict.org';

main( @ARGV );
exit;

sub main {
    initialize( @_ );

    for my $word ( @_ ) {
    my $definitions = $DICT->define( $word );
    for my $definition ( @$definitions ) {
        print dictionary_name( $definition->[0] )
        . "\n$definition->[1]\n";
    }
    }

    1;
}

sub initialize {
    $DICT = Net::Dict->new( $DICT_HOST,
                %DICT_PARAMS );

    $| = 1;

    1;
}

{
    my %dicts;
    sub dictionary_name {
    my $dict = shift;
    $dicts{$dict} ||= $DICT->dbTitle( $dict );
    }
}

__END__

=pod

=head1 NAME

dict - a simple client for http://dict.org

=head1 SYNOPSIS

 dict insufflation

 (define-word "insufflation")

 C-x d

=head1 EMACS BINDING

Emacs is a great place to bind all sorts things together and this is
no exception. Add this to your .emacs file to create the function
DEFINE-WORD. If you don't give it a word then it will attempt to
define whatever word is currently under your point.

 (defun define-word (input-word)
   "Define a word using http://dict.org."
   (interactive "MWord to define: ")
   (let ((buf (generate-new-buffer "*dict*"))
         (word (if (> (length input-word) 0)
                   input-word
                 (current-word))))
     (shell-command (concat "~/bin/dict " word) buf)
     buf))

The following command binds C-x d to the function.

 (global-set-key "\C-xd" 'define-word)

=end
Replies are listed 'Best First'.
Re: dict.org cli lookup
by belg4mit (Prior) on Dec 12, 2004 at 23:25 UTC
    Question, why on earth would you do this instead of using the dict protocol? Say with Net::Dict?

    --
    I'm not belgian but I play one on TV.

      When I asked people if they knew of a dict.org command line client, no one mentioned that Net::Dict existed. Here's a copy of the original source.

        Well a CLI is a horse of a different color altogether. The reference server implementation comes with a good client. From the links section off the main page ftp://ftp.dict.org/pub/dict

        --
        I'm not belgian but I play one on TV.

Re: dict.org cli lookup
by tmoertel (Chaplain) on Dec 13, 2004 at 02:58 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://414072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2020-10-21 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (212 votes). Check out past polls.

    Notices?