next up previous contents index
Next: Appendix Up: Hangman Previous: Add a Body Part?   Contents   Index


Fill in the spaces

At the center of the program, 'Is the letter in the word?' directs traffic. We'll make the subroutine `fill_in_space':

    sub fill_in_space {
        $letter = $_[0]; 
        $match = 0;
        foreach $l (0..$number_of_letters-1){
            # Is the letter in the word?
            if($letter eq $letters[$l]){
                # If it is, fill in the correct space.
                $word_so_far[$l] = $letter;
                # Remember after the foreach loop
                $match = 1;
                # Keep track of correct guesses
                $good_guesses++;
            }
         }
         return $match; # True if the letter is in the word.
    }



Tom Hunt 2002-06-09