sub guess { my $self = shift; my $word = shift; chop($word); if ($self->chances == 0) { return undef; } #orginally, '$letter' was made from the shift(). I #changed it to $word, and got '$letter' from the 1st #character in $word. my $letter = substr($word,0,1); #Don't want to type $self->secret() twice. my $secret = $self->secret(); push (@{$self->{guesses}}, $letter); #If you correctly guess the name, then push the #entire thing to guesses. push (@{$self->{guesses}}, $word) if ($secret eq $word); if ($secret =~ /$letter/){ $self->{score} += $self->chances + 1; } else { $self->{chances}--; } } } package main; my $ua = LWP::UserAgent->new(); my $response = $ua->get("http://www.perlmonks.org/index.pl?node_id=15851"); die $response->code() if $response->code() != 200; my $content = $response->content(); my $cblist = XMLin($content); my @user = map $_->{username}, @{$cblist->{user}}; my $monk = $user[rand @user]; #my $g = Games::GuessWord->new(words => [$monk]); my $g = new GamesGuesswordExtended($monk); # Uncomment out the following for testing print "Secret: " . $g->secret . "\n"; my @guesses = $g->guesses; do{ print "Guesses Remaining:" . $g->chances . "\n"; print "The Monk is: " . $g->answer . "\n"; print "What is your Guess?: "; my $response = <>; $g->guess($response); if ($g->won) { print "Yep, it was " . $g->secret . "...Great Guess!\n"; exit; } }until($g->chances<=0); print "Sorry, the monk was: " . $g->secret . "\n"