#!/usr/bin/perldb -w
# FILE:  create_db.pl
# Demonstrates:
#    creating a database from within a Perl program,
#    adding a record to a database,
#    checking for the existence of a record in a db,
#    deleting a record from a db. 

use DB_File;      #load database module

$dbname = "test.db";
#Open database, to be accessed through %HASH:
tie %HASH, "DB_File", $dbname or die "Can't open $dbname :$!\n";

#insert some items into the database:
$HASH{101} = "Darron Absher";
$HASH{102} = "Emeka Anadu";
$HASH{103} = "Matthew Cross";
$HASH{104} = "Shelly Ferrell";
$HASH{105} = "Andy Forester";

#check whether in database:
if (exists $HASH{104})
{
  print "$HASH{104} is in the database.\n";
}
else
{
  print "Not in database.\n";
}

#delete from database:
delete($HASH{104});

#now check again for existence:
if (exists $HASH{104})
{
  print "$HASH{104} is in the database.\n";
}
else
{
  print "Not in database.\n";
}
untie %HASH;
