Merge pull request #3 from warthurton/master

Added regex to dice/goodie.pl
master
Wayne Arthurton 2011-08-10 19:57:09 -07:00
commit 0e5ba02252
2 changed files with 26 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# Choose between the values stored in @choices
# Choose between the values matched between 'or' in input
use strict;
use warnings;

View File

@ -4,6 +4,28 @@
use strict;
use warnings;
my $choices = 6;
my $choice = int(rand($choices)) + 1;
print "$choice\n";
my $q_check_lc = 'throw 5 dice';
my $answer_results = '';
my $answer_type = 'dice_side';
my $choices = 6; # To be replace with input string in the future
if ( $q_check_lc =~ m/^throw(?:\sdie|(\d{0,2}\s)*dice)$/ ) {
my $rolls = 1; # If "die" is entered
if (defined($1)) { # Not defined if number of "dice" not specified
if ($1 eq " ") {
$rolls = 2;
}
else {
$rolls = $1;
}
}
for (1 .. $rolls) {
my $roll = int(rand($choices)) + 1;
$answer_results .= " $roll";
}
print qq($answer_type\t$answer_results\n);
}