This is not an answer to your question, but you can utilize regular expressions and the matching operation modifier e to evaluate the expression for you:
for my $input (<DATA>) { chomp $input; (my $eval = $input) =~ s/(\d+)d(\d+)(.*)/$1*(int(rand$2)+1)+$3/e; printf "%10s = %i\n", $input, $eval; } __DATA__ 2d9+100 1d20+10 1d3+100 50d10-5
Good luck, and perhaps the information found here can help: Make a Text Based RPG
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: How to add input history
by jeffa
in thread How to add input history
by zsl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |