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:

%current = ( 'word' => "", 'tries_left' => "", 'letters' => "", 'revealed' => "", );
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...)


In reply to Character positioning by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.