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

#######################################################
# lect08_dbm2
#
# 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
#######################################################

# open an existing OR create a new DBM file, accessible
#    via a DBM hash

dbmopen(%HIGH_SCORES, "score_db", 0644)
    or die "Cannot create score_db: $!";

# let's try to maintain high scores for people
#    in this little database

print "Whose score do you wish to possibly update? ";
chomp(my $scorer = <STDIN>);

print "What is ${scorer}'s score? ";
chomp(my $score = <STDIN>);

# if there's NO previous value stored for $scorer,
#    or existing score is lower,
#    then we should update this $scorer's high score

if ( (! defined( $HIGH_SCORES{ $scorer } ))
     || ($HIGH_SCORES{ $scorer } < $score ))
{ 
    $HIGH_SCORES{ $scorer } = $score;
    print "new high score of $score for $scorer has been recorded;\n";
}

else
{
    print "$scorer had an equal or higher score than that: ",
          $HIGH_SCORES{ $scorer }, "\n";
    print "   NO change was recorded.\n";
}

print "\n";

# end of lect08_dbm2