Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Can someone help with my code?  When the user enters "c" in the text
box it fills in c_ _, which is great.  But when they enter the next
letter, like "a".  It erases the c_ _ and produces _ a _.  I need to
keep it to be ca_.  Also how do you get the number of wrong guesses in
a string?  Example, j,l,u,v etc.so the user knows the letters they have

use CGI ':standard';

use CGI::Carp  'fatalsToBrowser';

use constant MAX_MISSES => 8;


my $word;
$word = "cat";
    my $misses_left = MAX_MISSES;
     my %letters = map {$_ => 1} split //, $word;;
     my %guesses = ();

if (param()) {

    my $guess = param('guess');

sub processguess{

if (exists $guesses) {
           print qq(You\'ve already guessed "$guess".\n);



      if (exists $letters) {
         delete $letters;
         keys %letters or last GUESSES;

       } else {
         print "another";

       if ($misses_left > 0)
       print "Your guess is: ", join(' ', sort keys %guesses), "\n";
       print "You have $misses_left misses left.\n\n";
       print join(' ', map {exists $guesses ? $_ : '_'} split //,
$word), "\n";
           my $guess;


    sub display {

        my $the_cookie = cookie (

        print header(-cookie=>$the_cookie),


            "Tries Remaining: ",
             "The word: ",
            "Letters guessed so far: ",

            "Next Guess: ",
            textfield (

            submit (-name=>"submit", -label=>"Guess"),
            submit (-name=>"new_game", -label=>"New Game"),

Re: Hangman

weberw@adelphia.net wrote:
Quoted text here. Click to load it

Didn't you like the responses that you got in CLPMisc?
Anyway, as you are asking in CLPModules the answer is
http://search.cpan.org/search?query=hangman&mode=all, of course.


Re: Hangman

J=FCrgen Exner wrote:
Quoted text here. Click to load it

or perl.beginners...  this guy was really hedging his bets...


Site Timeline