Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect08_dbm1
#
# a first example of a DBM file and DBM hash.
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 10-12-04
#######################################################

# associate a DBM database file with a DBM hash:
#    PERL STYLE TRADITION: DBM hash nameis written in
#    all-caps, so it "looks" filehandle-ish

dbmopen(%DATA, "my_database", 0644)
    or die "Cannot create my_database: $!";

$DATA{"fred"} = "bedrock";

print "give the next person: ";

# UNCOMMENT the following line if on a Windows system
#    and first <STDIN> is being ignored...
# my $trash = <STDIN>;

chomp(my $person = <STDIN>);

print "give their hometown: ";
chomp(my $town = <STDIN>);

$DATA{ $person } = $town;

while (my($key, $value) = each(%DATA))
{
    print "$key has value of $value\n";
}

# clean up/close the DBM file when done

dbmclose(%DATA);

# end of lect08_dbm1