laziness, impatience, and hubris | |
PerlMonks |
Re^3: hangman gameby Athanasius (Archbishop) |
on May 28, 2015 at 15:15 UTC ( [id://1128149]=note: print w/replies, xml ) | Need Help?? |
Hello mbgbioinfo, It’s a pity you haven’t followed Marto’s advice to use strict and to properly indent your code. You are making it much harder on yourself by not doing so. :-( To use SEEK_SET, you need to add use Fcntl ':seek'; at the top of your script. See seek and Fcntl. Now to the main issue:
There is no point in adding chomp here, it accomplishes nothing. It is the variable $choice which has a terminal newline that needs to be removed:
I notice also that the following logic is wrong:
$letters[$i] is a single character, but $guess is a string of characters. You need to compare each letter of $choice with the corresponding letter in $guess. (And when you re-write that loop, be careful to ensure that $i never exceeds the index of the last letter in the shorter of the two strings.) P.S. Whenever you update a post (in this case, your OP), please leave the original intact and clearly mark additions as updates, so that monks coming to this thread in the future will be able to make sense of the replies. Hope that helps, Update: Re-wrote the P.S. to make it clear that when updates are added, the original should not be removed.
In Section
Seekers of Perl Wisdom
|
|