Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

phpmyadmin fehler rechte unerlaubte mischung, WWWXXXApc, lilo trying to map files from unnamed device 0x0000", Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error

Links

XODOX
Impressum
Datenschutz

#1: explicit package name

Posted on 2011-10-04 04:59:37 by 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 = <STDIN>);
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/

Report this message

#2: Re: explicit package name

Posted on 2011-10-04 05:15:29 by 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/

Report this message

#3: Re: explicit package name

Posted on 2011-10-04 05:17:04 by 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 =<STDIN>);
> 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/

Report this message

#4: Re: explicit package name

Posted on 2011-10-04 05:19:10 by 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/

Report this message