Wait, oops. I forgot to add an extra if clause. The new code looks like:
#!/usr/bin/perl use warnings; use strict; my $up = "\e[A"; my @history = []; my $number = 10; 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 eq $up) { $dice = $history[-1]; } elsif ($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; }
When I run it, the up arrow doesn't cause any error messages, but it doesn't do anything either:
Input the dice and modifier you want to roll like this: 2d9+100. To qu +it, press Ctrl-C. 2d9+100 109 101 ^[[A ^C
In reply to Re^3: How to add input history
by zsl
in thread How to add input history
by zsl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |