in reply to hangman question
$#letters is the index of the last element in @letters (or -1 if there are no elements). $blankword[$i] accesses the element at index $i of @blankword. The loop foreach $i (0..$#letters) {...} prints each of the known letters in the word and prints a '-' for any unknown letters. The if ($blankword[$i]) tests to see if a letter is known or unknown by testing to see if the element is zero or not.
In scalar context @array returns the number of elements in @array (cf $#array above). So $guesses[@guesses]=$guess; assigns $guess to the next unused element in @guesses. It would be more Perlish to push @guesses, $guess instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hangman question
by convenientstore (Pilgrim) on Jul 16, 2007 at 00:37 UTC | |
by GrandFather (Saint) on Jul 16, 2007 at 01:46 UTC | |
by convenientstore (Pilgrim) on Jul 16, 2007 at 02:00 UTC | |
by ysth (Canon) on Jul 16, 2007 at 02:46 UTC | |
by convenientstore (Pilgrim) on Jul 16, 2007 at 03:48 UTC |