in reply to Re^2: setup of a small perl game
in thread setup of a small perl game

The quick fix would be to insert a last after the "Congratulations" line, like this:

{ print "Congratulations! The scrambled word was $word.\n\n"; last; }
but IMHO I would advice you to follow the structure I gave you more closely; I think you will find that your script is clearer, and more easily modified and debugged if you actually implement functions like check_answer(), etc., that I used in the "wishfulthinking code". The more your code looks like pseudocode, the clearer it will be.

the lowliest monk

Replies are listed 'Best First'.
Re^4: setup of a small perl game
by Anonymous Monk on Apr 12, 2005 at 04:10 UTC
    last; did fix it, thanks!

    You are probably right, functions might be easier to debug later. By functions do you mean sub routines? I could probably do that. I'm not too versed with self-made functions, however.

      Yes, subroutines. Subs are one of the most powerful ways to tame code complexity; without them you quickly end up with huge, monolithic scripts that are impossible to read, modify, or debug. Read perlsub, and soon you'll be sub genius. :-)

      the lowliest monk

        Although I like the overall syntax and simplicity of the pseudocode it does bring two things to my attention.

        1) You need to predeclare the variables at the top of the script otherwise when working in subs you'll get blasted with errrors, especially under strict.

        2) Not being one of the "sub geniuses" myself, I don't think you can get by using last; inside of a sub routine and at the moment I can't think of a different way to go about doing that.



        "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

        sulfericacid