Subject: array

Hi:
I want to write a code storing in "memory" a list of numerical values and 
then asking the user to guess a number, if that number matches one in 
memory, program should exit; otherwise keep asking...

**********************************
#!/usr/bin/perl
use warnings;
use strict;
my (@memory, $guess);
@memory = (3..8);
print "Guess whats in memory?  \n";
$guess = <STDIN>;
while ($guess != $memory[$_])
{
print "Wrong, try again.... \n";
$guess = <STDIN>;
}
**************************************

In the @memory array when i put a range, the loop seems to always go on even

if number "guessed" is in "memory" with the error message...
Guess whats in memory?
4
Use of uninitialized value in array element at curr.plx line 8, <STDIN> line

1.
Wrong, try again....
5
Use of uninitialized value in array element at curr.plx line 8, <STDIN> line

2.
Wrong, try again....

Any suggestions appreciated!
Cheers
Vineet

<snip>
%is_good = map{$_ , 'Y'} @memory;
while (!exists($is_good{$guess))) {
</snip>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to