Vineet Pande wrote: > Hi: Hello,
> 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[$_]) You haven't assigned a value to $_ which is why you get the warning "Use of uninitialized value in array element", however perl will automatically evaluate undef as zero in that context so you are always comparing the value of $guess with the value of $memory[0]. You should also chomp() the $guess variable to remove the unneeded newline. > { > 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! John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>