explicit package name

explicit package name

am 04.10.2011 04:59:37 von Chris Stinemetz

Can someone tell me why I am getting the following error?

Global symbol "$quess" requires explicit package name at ./ex10-1.pl line 18.
Execution of ./ex10-1.pl aborted due to compilation errors.

I declare $guess inside the while loop. Shouldn't that suffice for the
rest of the scope?

Thank you,

Chris

#!/usr/bin/perl

use warnings;
use strict;

my $secret = int(1 + rand 100);
# This next line may be uncommented during debugging
print "Don't tell anyone, but the secret number is $secret\n";

while (1) {
print "Please enter a guess from 1 to 100: ";
chomp(my $guess = );
if ($guess =~ /quit|exit|^\s*$/i) {
print "Sorry you gave up. The number was $secret.\n";
last;
} elsif ($guess < $secret) {
print "Too small. Try again!\n";
} elsif ($quess == $secret) {
print "That was it!\n";
last;
} else {
print "Too large. Try agian!\n";
}
}

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: explicit package name

am 04.10.2011 05:15:29 von jwkrahn

Chris Stinemetz wrote:
> Can someone tell me why I am getting the following error?
>
> Global symbol "$quess" requires explicit package name at ./ex10-1.pl line 18.
> Execution of ./ex10-1.pl aborted due to compilation errors.
>
> I declare $guess inside the while loop. Shouldn't that suffice for the
> rest of the scope?

You declare $guess but the error message says "$quess" (a Q instead of a G).



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: explicit package name

am 04.10.2011 05:17:04 von Rob Dixon

On 04/10/2011 03:59, Chris Stinemetz wrote:
> Can someone tell me why I am getting the following error?
>
> Global symbol "$quess" requires explicit package name at ./ex10-1.pl line 18.
> Execution of ./ex10-1.pl aborted due to compilation errors.
>
> I declare $guess inside the while loop. Shouldn't that suffice for the
> rest of the scope?
>
> Thank you,
>
> Chris
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my $secret = int(1 + rand 100);
> # This next line may be uncommented during debugging
> print "Don't tell anyone, but the secret number is $secret\n";
>
> while (1) {
> print "Please enter a guess from 1 to 100: ";
> chomp(my $guess =);
> if ($guess =~ /quit|exit|^\s*$/i) {
> print "Sorry you gave up. The number was $secret.\n";
> last;
> } elsif ($guess< $secret) {
> print "Too small. Try again!\n";
> } elsif ($quess == $secret) {

You have correctly declared the variable $guess, but you are using
$quess here, which doesn't exist. That is the sort of thing 'use strict'
is good at finding for you!

> print "That was it!\n";
> last;
> } else {
> print "Too large. Try agian!\n";
> }
> }

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: explicit package name

am 04.10.2011 05:19:10 von Chris Stinemetz

>
> You have correctly declared the variable $guess, but you are using
> $quess here, which doesn't exist. That is the sort of thing 'use strict'
> is good at finding for you!
>

Oh my goodness! Maybe that is a sign it is time to call it a night!

Thanks all! Not sure why I couldn't see that.

Chris

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/