Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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__.%current = ( 'word' => "", 'tries_left' => "", 'letters' => "", 'revealed' => "", );
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...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lost...
by djantzen (Priest) on Nov 25, 2002 at 07:12 UTC | |
|
Re: Lost...
by Chmrr (Vicar) on Nov 25, 2002 at 07:22 UTC | |
|
Re: Lost...
by japhy (Canon) on Nov 25, 2002 at 07:43 UTC | |
|
Re: Character Positioning
by tadman (Prior) on Nov 25, 2002 at 07:48 UTC | |
|
Re: Character positioning
by mce (Curate) on Nov 25, 2002 at 12:09 UTC | |
|
Re: Character positioning
by UnderMine (Friar) on Nov 25, 2002 at 13:19 UTC |