PERL I/O question

Playing with an until loop as follows:

my $input;

until ($input eq "quit") {
print "Please enter something:";
$input = <STDIN>;
chomp $input;
if ($input eq "dog") {
print "cat" ;
}
else {
print "Please re-enter";
}
}

Something simple like this...

I want to prompt the user to enter something. Whatever they enter, print something and ask again, unless they say "quit" and then quit.

Trying to get a handle on the until() loop and am either getting one of the following problems:

  1. Infinite loop/print on "please enter something"
  2. The program quits after I enter something

"until" is not a loop, it is a condition. What you want is "while". "while" is a loop and you can use loop commands to control the loop:

next
redo
last

The old standard for what you are doing is:

while(1){
   ...
}  

heres a working example I recently posted on another forum:

use strict;
use warnings;

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

Actually, you can do this:

use strict;
use warnings;

my $thinkingof = int(rand 10)+1;
until (0) {
   print "Pick a number 1 to 10\n";
   my $guess = <STDIN>;
   chomp $guess;
   if ($guess > $thinkingof){
      print "You guessed too high\n";
      next;
   }
   elsif ($guess < $thinkingof){
      print "You guessed too low\n";
      next;
   }
   print "YOU GUESSED RIGHT!! It was $guess\n";
   last;
}

Great, thanks. I'll need to look into how and why this works. But it did.