#!/usr/bin/perl -w # FILE: create_staff_db # 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 = "staff.db"; #Open database, to be accessed through %HASH: tie %info, "DB_File", $dbname or die "Can't open $dbname :$!\n"; #insert some items into the database: $info{104} = "Lincoln Stein"; $info{101} = "George Washington"; $info{102} = "Martha Washington"; $info{133} = "Elvis Presley"; $info{114} = "Alice N. Wonderland"; $info{105} = "Felix Garcia"; $info{199} = "P. Smith"; #check whether in database: if (exists $info{199}) { print "$info{199} is in the database.\n"; } else { print "Not in database.\n"; } #delete from database: delete($info{199}); #now check again for existence: if (exists $info{199}) { print "$info{199} is in the database.\n"; } else { print "Not in database.\n"; } untie %info;