-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_d100_list.pl
executable file
·47 lines (40 loc) · 1.02 KB
/
make_d100_list.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w
use strict;
my @ary;
my $count = 1;
while (<>) {
chomp;
push(@ary, $_);
}
my $mult = length(sprintf("%d", scalar @ary));
my $die_size = 10**$mult;
my $inc = ($die_size/(scalar @ary))-1;
print "Roll 1d$die_size\n";
foreach my $entry (@ary) {
my $dice = "";
if (int($count) == int($count+$inc)) {
$dice = sprintf("%d", int($count));
} else {
$dice = sprintf("%d - %d", int($count), int($count+$inc))
}
&print_dice($dice, $entry);
$count += $inc+1;
}
if (int($count) <= $die_size) {
my $entry = "Roll twice";
my $dice = sprintf("%d - %d", int($count), $die_size);
if (int($count) == $die_size) {
$dice = int($count);
}
&print_dice($dice, $entry);
}
# Amazing weird Perl format crap.
# http://perldoc.perl.org/perlform.html
sub print_dice {
no warnings;
my ($dice, $entry) = @_;
my $format = sprintf("format STDOUT =\n@%s @*\n%s, %s\n.\n",
'|'x(($mult*2)+5), '$dice', '$entry');
eval $format;
write;
}