Thanks, stevieb! I've updated my program to account for warnings raised when input lacks a modifier, but there's a problem. Am I using your technique right?
#!/usr/bin/perl use warnings; use strict; my $up = "\e[A"; my @history = []; print "Input the dice and modifier you want to roll like this: 2d9+100 +. To quit, press Ctrl-C.\n"; while (1) { my $dice = <>; chomp $dice; my @arr = split (/d/, $dice); if ($dice =~ /\+/) { my @arr2 = split (/\+/, $arr[1]); $arr2[0]++; for my $i (1 .. $arr[0]) { print ((int(rand($arr2[0] - 1)) + 1 + $arr2[1]), "\n"); } } else { $arr[1]++; for my $i (1 .. $arr[0]) { print ((int(rand($arr[1] - 1)) + 1), "\n"); } } push @history, $dice; }
Whenever I use this code, I get this problem:
zsl@pc:~/codefolder $ perl dieroller.pl Input the dice and modifier you want to roll like this: 2d9+100. To qu +it, press Ctrl-C. 2d9+100 101 101 ^[[A Argument "^[[A" isn't numeric in foreach loop entry at DDDR.pl line 19 +, <> line 2. ^C zsl@pc:~/codefolder $
In reply to Re^2: How to add input history
by zsl
in thread How to add input history
by zsl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |