http://qs321.pair.com?node_id=475097
Category: Fun Stuff
Author/Contact Info cryptoquip jennyjo@gmail.com
Description: This is just a simple little guess-the-number game, and basically my first script after "Hello world." ;-) It works, but I'm sure it could be smoother. Comments welcome.
#Guessing Game
#You only get 10 tries!
#Gives the option of starting over.
#This version should count your turns for you, down from #ten.

TOP:
my $tries = 10;
#This is how many guesses you get.

my $value = int(rand(200));
#This is the number they have to guess: a random integer.

print "Pick a number between 0 and 200.\n";
print "You have ";
print $tries;
print " guesses left.\n";
$tries--;


my $guess = <STDIN>;

until ($tries==0){
    if($guess>$value){
    print "You need to guess a lower number.\n";
    print "Guesses left: ";    
    print $tries;
    print "\n";
    $tries--;
    $guess = <STDIN>;
    }elsif($guess<$value){
    print "You need to guess a higher number.\n";
    print "Guesses left: ";    
    print $tries;
    print "\n";
    $tries--;
    $guess = <STDIN>;
    }else{
    print "You guessed my number in ";
    print (10-$tries);
    print " guesses.  Thanks for playing. \n";
    $tries=0}
}

if ($guess != $value){
    print "Sorry, you ran out of guesses.  My number was ";
    print $value;
    print ". \n"; 
}

print "Play Again? (y/n) \n";

my $again = <STDIN>;

chomp ($again);

if($again eq "y"){
goto TOP;
}else{
print "Goodbye!";
}