# leave $vMax undefined initially so we don't need to # guess at the lowest value; this also lets us know we # never actually looked for a maximum on the off-chance # that our hash is empty my ($kMax,$vMax); while(my ($k,$v) = each(%someHash)) { # if this is the first key,value pair, initialize $kMax,$vMax # otherwise only reset on a new maximum if (!defined($vMax) || ($v > $vMax)) { $kMax = $k; $vMax = $v; } } if (!defined($vMax)) { print "No entries in my hash table!\n"; } else { print "key at maximum=$kMax, maximum value=$vMax\n"; }