PDA

View Full Version : counting the letters in a word


ignoranceisblis
03-04-2005, 08:35 PM
I'm trying to write a hangman game but I'm not sure how to count the letters of a variable
I need a way to say

my $hangman = "medical"; # random word to play with
if ($response =~ /@letters/) { # $response is the user's ressponse and $letters is all the letters of $hangman
@knownletters = @knowletters + $response; # somehow :)
}
somhow replace all the letters of hangman that we don't know about with under scores

print $hangman;

I could think of a couuple long drawn out ways of accomplishing this but I wanted to see if anyone had any ideas first.
Is there an easy way to do this?

mlseim
03-05-2005, 04:12 AM
Perl's strongest asset is it's ability to process strings.

It's a great learning experience to write a hangman game.
I suggest looking at some tutorials on a Google Search.

... and, there's more than one way to answer your question.

The BEST way is to look at some other examples and learn
from examining and experimenting with another script...

http://www.google.com/search?q=perl+hangman+script&btnG=Search

You'll find a lot to look at :thumbsup:



.