Created
June 12, 2014 01:44
-
-
Save yashigani/59f764063ec533364f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use 5.010; | |
my $debug = $ENV{DEBUG} // 1; | |
my $answer = int(1 + rand 100); | |
say "answer is $answer" if $debug; | |
GAME: { | |
print "Input number(1-100): "; | |
chomp(my $word = <STDIN>); | |
my @commands = ("", "quit", "exit"); | |
foreach (@commands) { | |
if ($_ eq $word) { | |
last GAME; | |
} | |
} | |
if (not($word =~ /\d+/)) { | |
say "$word is not a number!"; | |
redo; | |
} | |
elsif ($answer == $word) { | |
say "You win!"; | |
} | |
else { | |
my $hint; | |
if ($answer < $word) { | |
$hint = "Too high"; | |
} | |
elsif ($answer > $word) { | |
$hint = "Too low"; | |
} | |
say $hint; | |
redo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment