Perl: the Markov chain saw | |
PerlMonks |
Assigning a file to an Array.by elle45purple (Initiate) |
on Feb 12, 2009 at 15:08 UTC ( [id://743335]=perlquestion: print w/replies, xml ) | Need Help?? |
elle45purple has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks!
I'm new to perl and wanted to ask the people here if they could help me fix a simple
hangman program that i cant get to work.
I'm trying to get this program to open the file "dictionary.txt"
Then i want to assign that file to @words. However, immediately there's a problem with that, two question marks pop up at the beginning which were not in the original file (I've tried using the chomp function).
I then want to choose a word at random from that file and split it so that each letter is a different element in @letters so that i can turn the number of elements into a single number. The array @blankword is used to mark which letter the player has guessed successfully. (0) x scalar(@letters) creates a list that is as long as the number of elements in @letters, which is stored in @blankword. As letters are guessed, these 0s are changed to letters which will mark the positions of the correctly guessed letters.But the number of 0s are always too many.
This is the code for my program.
The following code works ok but i cant seem to change it to get it to choose the words from the dictionary file.
and here is the contents of the dictionary file which i think should be readable from perls perspective. Printer Internet Mouse Keyboard Monitor Thank you for reading this and i would appreciate it very much if you could help me. elle45purple
Back to
Seekers of Perl Wisdom
|
|