如何在生成方程式的运算符中转换 perl 变量?

How to convert a perl variable in a operator for make equations?

my $numA= $ARGV[0]; #5
my $numB= $ARGV[1]; #5
my $func= $ARGV[2]; #+

my $result = $numA .$func . $numB; #The result shoudl be 10

print "The result is:  $result"; # The result is: 5+5

我有这段代码,我想获取“$func”作为运算符以将“$numA”与“$numB”相加。

表达式已经解析了,方便

my %ops = (
   '+' => sub { $_[0] + $_[1] },
   '-' => sub { $_[0] - $_[1] },
   '*' => sub { $_[0] * $_[1] },
   '/' => sub { $_[0] / $_[1] },
);

my ($operand1, $operand2, $operator) = @ARGV;

say $ops{$operator}->($operand1, $operand2);