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...)
In reply to Character positioning by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |