Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.46 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3.  
  4. while (1)
  5.   {
  6.   print "What would you like to roll?\nFormat Ex.  1d20, 2d6, 1d4, etc...\n";
  7.   my $input = <>;
  8.  
  9.   if ($input =~ /^(\d+)d(\d+)$/)
  10.     {
  11.     unless ($2)
  12.       {
  13.       print "d0 not supported.\n\n";
  14.       next;
  15.       }
  16.  
  17.     my $d = 0;
  18.     $d += 1 + int(rand($2)) for (1..$1);
  19.  
  20.     print "you rolled $1 d$2 for: \n$d\n";
  21.     }
  22.   else
  23.     {
  24.     print "Invalid format or no input given.\n\n";
  25.     }
  26.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement