#!/usr/bin/perl
#
# Script for creating the asnet database (overwrites any existing values)
# Authors: Stephane Boyera/Jose Kahan W3C/INRIA
#

use NDBM_File;

#if ( $#ARGV ne 0 ){ &usage }

($dbm, $file, $force)=@ARGV;

if (!$dbm || !$file)
{
   &usage;
}

sub usage {
print "Usage: $0  dbm_base file containing key value\n" ;
exit -1;
}

open (KV,"$file") || die ("Error: couldn't open $file\n");

dbmopen(%BASE,"$dbm",0660);

# we first clean the dbm base.
foreach $key (keys %BASE) {
	delete $BASE{$key};
}

# write in the key, data info
while (<KV>)
  {
   $line=$_;
   chop $line;
   ($key,@value)=split(' ',$line);
   $value = join (' ', @value);
   if (defined ($BASE{$key}))
   {
     print "The entry $key exist and the value associated is $BASE{$key} \n";
     print "replacing the existing entry with $value\n";
   }
   $BASE{$key}=$value;

   print "$key = $value\n";
  }
dbmclose (%BASE);
