XP is just a number | |
PerlMonks |
Character positioningby Anonymous Monk |
on Nov 25, 2002 at 06:50 UTC ( [id://215572]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
First off, while this is a question related to a homework
assignment, I certainly don't want anyone doing my
homework for me. Mostly, what I'm looking for is some
idea as to a reasonable path to my goal, with maybe
some warnings as to what to watch out for along the
way. If someone want's to give me some actual code,
keen, but that's not my primary goal.
I'm working on a CGI hangman program, using the CGI.PM module to handle the CGI stuff. What I'm stuck on right now is the subroutine to reveal the word, called (imaginatively enough) reveal_word. My data structure looks like this: I start by setting revealed to be a number of _ equal to how many letters are in word. Then a user makes a guess, I check and see if it's in the word, and if it is, I want to have revealed end up getting the guess (one letter) into the right "slot", with the rest of them still being _. So a guess of c with the word being cat should give me c__. The problem is, I've no idea how to do this. It's not adding the guessed letter, it's adding it in the right place I can't figure out. How can I put that letter where I want it? Is there some clever thing involving s/// I should be trying? Or should I be completely rebuilding what goes into $current{'revealed'}? Or is there some perl command that'll just do it for me that I just can't find anywhere in my friendly O'Reilly books or over on CPAN? Thanks, ~Pax update (broquaint): added some formatting and changed the title (was Lost...)
Back to
Seekers of Perl Wisdom
|
|