#!/usr/bin/perl -w
use strict;
use DB_File;
use Net::Dict;

# Make a connection to a dictionary server.
my $server   = shift || 'dict.org';
my $database = shift || 'web1913';

my $dict = Net::Dict->new($server, Debug => 0) or
    die "Can't reach $server to fetch dictionary entries.\n";
$dict->setDicts($database);

print 'Fetch the lexicon from ', $dict->dbTitle($database),
    " (and save it as a dbm).\n";

# Open our lexicon dbm.
my %lexicon;
tie %lexicon, 'DB_File', 'lexicon' or
    die "Can't tie to ./lexicon - $!\n";

# Add the suffixes and prefixes to the lexicon (without
# definitions).
for (qw(^[a-z].*-$ ^-[a-z].*$)) {
    @lexicon{ map { $_->[1] } @{ $dict->match($_, 're') } } = ();
}

# Close our dbm lexicon.
untie %lexicon;
