Aye,

although I agree with Jonatha's rewrite of your loop, he actually didn't
answer your question for *why* your code doesn't work:

On Fri, Apr 05, 2002 at 04:16:42PM -0800, Jaimee Spencer wrote:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
>         print ("What is 7 times 7? \n");
> 
> chop(my$input_answer = <STDIN>);
> my$answer = 49;
> 
> until($input_answer == $answer) {
>        print ("No that is wrong! Try again. \n");
>        chop(my$input_answer = <STDIN>);

Here =========^^ 's your problem.

You *re*declaring $input_answer inside the until block.  The 'until'
sees the outer variable that you only entered once.  The newer input
variable is hidden inside the surrounding curly braces and never reaches
the 'until' clause.

Read 'perldoc perlsyn' and look for the section called 

    Compound statements

The concept of a 'scope' is explained here.  Also read about 'lexically
declared variables' - I dunno where exactly that stuff is documented.

Leaving out the 'my' is what's solving your problem, because you don't
declare a new '$input_answer' then, but continue to use the previously
used one.

-- 
                       If we fail, we will lose the war.

Michael Lamertz                        |      +49 221 445420 / +49 171 6900 310
Nordstr. 49                            |                       [EMAIL PROTECTED]
50733 Cologne                          |                 http://www.lamertz.net
Germany                                |               http://www.perl-ronin.de 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to