Skip to content

Instantly share code, notes, and snippets.

@jhannah
Created December 21, 2009 17:30
Show Gist options
  • Save jhannah/261092 to your computer and use it in GitHub Desktop.
Save jhannah/261092 to your computer and use it in GitHub Desktop.
my $answer;
while (! $answer) {
$answer = prompt();
}
if ($answer == 1) {
print "you chose foo\n";
} elsif ($answer == 2) {
print "you chose bar\n";
} elsif ($answer == 3) {
print "you chose baz\n";
}
sub prompt {
my $menu = <<EOT;
What do you want me to do?
(1) Foo
(2) Bar
(3) Baz
EOT
print "$menu> ";
my $answer = <STDIN>;
chomp $answer;
return undef unless ($answer =~ /^(1|2|3)$/);
return $answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment