I'm puzzled as to why not declaring my $guess; as opposed to using my $code = <STDIN>; didn't really work. Is it because by using this last statement confilicts with the while ($guess = <STDIN>) statement? I've kept some comments in as they show my different attempts to make this work. Thank you for any advice you can offer on my problem. I'm sure there are leaner ways to design this program, but I am just trying to understand the variables here rather than make it lean and mean.use strict; my $target = 12; print "Guess my number.\n"; #my $guess = <STDIN>; # Attempt 2 with the "next" statements below co +mmented out. This failed also. print "Enter your guess: "; #my $guess = <STDIN>; Attempt 1 worked but had to enter the guess a s +econd time on a new line before processing my $guess; while ( $guess = <STDIN>) { if ($guess == $target) { print "You guessed it!"; last; }elsif ($guess > $target) { print "Your guess is too high.\n"; #next; # Attempt 1 using this failed. }elsif ($guess < $target) { print "Your guess is too low.\n"; #next; # Attempt 1 using this failed. } print "Enter your guess: "; }
In reply to Regarding Declaring Variables by Tech77
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |