Skip to content

Instantly share code, notes, and snippets.

@yashigani
Created June 12, 2014 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashigani/59f764063ec533364f90 to your computer and use it in GitHub Desktop.
Save yashigani/59f764063ec533364f90 to your computer and use it in GitHub Desktop.
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