next up previous contents index
Next: Add a Body Part? Up: Hangman Previous: Keep track of correct   Contents   Index

Erase Guess

This subroutine sets $guess to the letter from the terminal and erases the letter from @alphabet.

Get a guess from the keyboard like sec.5.1, Terminal Input.

    sub erase_guess {
            chomp; # Trim the newline from $_
            $guess = lc($_); # convert to lower case
            # $i is an iteration variable for @alphabet
            # $alphabet[4] is 'e', $alphabet[13] is 'n', etc.
            $i = 0; 
            foreach $l (@alphabet){
                # Replace the letter with a space.
                if ($l eq $guess){
                     $alphabet[$i] = " ";
            last; # One letter at a time

Tom Hunt 2002-06-09