Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Help with Guessing Game

by BillKSmith (Deacon)
on May 12, 2013 at 03:47 UTC ( #1033166=note: print w/ replies, xml ) Need Help??


in reply to Help with Guessing Game

Your program has another serious bug. After it reports a win, it does not start a new game, but rather continues to prompt you to "Guess Again". Use strict and use warnings would find and report the error. (You have two variables named $guess) Of course this message tends to get lost in a sea of less serious error messages. Always use strict and warnings and fix all the errors that they report.

I have several comments on your style.

Most people (except perhaps old FORTRAN programers) find perl's do...while to be a bit quirky. Use them only when the offer a real advantage.

Do not append a newline to $rannumber. Better to chomp the newline from $guess.

You should separate code for validating input from real game code. Best to use a prompt modulue with a call back routine for validation.

UPDATE: Corrected typos

Bill


Comment on Re: Help with Guessing Game
Re^2: Help with Guessing Game
by davido (Archbishop) on May 12, 2013 at 04:28 UTC

    Best to use a prompt module with call back for validation.

    Sounds to me like IO::Prompt::Hooked (shameless plug).


    Dave

      Actually, I use ActiveState::Prompt. I will checkout your suggestion.

      You also made a great suggestion for keeping track of previous guesses.

      Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033166]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2015-07-01 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (11 votes), past polls