#!/usr/bin/perl

if ((scalar(@ARGV) == 0) || (grep /^-/, @ARGV)) {
    print "\n";
    print "  usage:  $0 <sourcefile> <dbmname> (<splitregex>)\n";
    print "\n";
    print "           adds elements in <sourcefile> to dbm <dbmname>\n";
    print "\n";
    print "           <sourcefile> is a text file of one-per-line\n";
    print "                <key> <splittoken> <value>\n";
    print "                (example: \".jp japan\")\n";
    print "           pairs, \n";
    print "\n";
    print "           <dbmname> the the basename of the dbm db\n";
    print "           (e.g. 'infobot-is')\n";
    print "\n";
    print "           the optional <splitregex> is the regular\n";
    print "           expression that defines the seperator between\n";
    print "           the key and the value in the input file.\n";
    print "           the default is simply white space.\n";

    print "\n";

    exit(1);
}

$sourcefile = $ARGV[0];
$dbname = $ARGV[1];

open(IN, $sourcefile) 
    || die "can\'t open $sourcefile as source\n";

dbmopen(db, $dbname, 0777) || die "Couldn't dbmopen \"$dbname\"";
$| = 1;

$split = " "; # "=>";

while (<IN>) {
    chomp;
    next if /^\s*$/;
    delete $db{$_};
    print "deleted $_\n";
}

close(IN);
dbmclose(db);
exit;
