I'm looking for the shortest or most optimized solution for a simple game that generates a random number from 1 to 10 and then asks a user to enter their guess. If the user guesses the number then it's a win, if they don't guess then the program should say that it was either more or less than that.
Here's my solution to this:
#c:\Perl\bin\Perl.exe
use strict;
use warnings;
my $guess = int(rand 10);
my $inp;
do{
print "Gimme your guess 1-10:\n";
$inp = <STDIN>;
chop($inp);
if ($inp > $guess){print "too much\n"}
if ($inp < $guess){print "too few\n"}
}while ($inp != $guess);
print "Bingo! It was: $guess";
What I'm looking for is some Perl magic. I don't have much Perl experience and I'd like to see some crazy Perl action here if it's true what they say about Perl scripts. Thanks for your time.