Im taking a perl class not exactly sure if what Im doing is right.
I was to take a written program that allowed the user to enter a number guessing what the target was. The original used elseif statements to let the user know if the guess was to high, too low, or correct. I need to make it so that it loops until the correct answer is given. Here is what I have so far. Any suggestions would be great.

#!/usr/bin/perl -w
# guessnum2.pl

use strict;

my $target = 12;
print "Guess my number!\n";
print "Enter your guess: ";
my $guess = <STDIN>;

if ($target == $guess)  {
	print "That's it!! You guessed correctly:\n";
while (<STDIN> > $target) {
	print "Your guess is too high!\n";
}
while (<STDIN> < $target) {
	print "Your guess is too low!\n";
}

Thanks, i went back and looked at the other thread. This is what I got out of it to make it work for what I needed. Does this make sense?

#!/usr/bin/perl -w
# guessnum2.pl

use strict;
use warnings;

my $target = 12;
while  {
   print "Pick a number\n";
   my $guess = <STDIN>;
   chomp $guess;
   if ($guess > $target){
      print "You guessed too high\n";
      next;
   }
   elsif ($guess < $target) {
      print "You guessed too low\n";
      next;
   }
   print "YOU GUESSED RIGHT!! It was $guess\n";
   last;
}

If you tried to run your code it will return a syntax error so I am suspicious you did not try it. In the other code the "while" loop has a condition:

while (1) {

why did you remove the condition in parenthesis?

This question has already been answered. Start a new discussion instead.