解决方法
最简单的方法:
print eval('5+2-1');
但这不安全:
print eval('print "You are hacked"');
您需要在评估之前检查字符串.
您也可以使用来自cpan的Math::Expression模块或许多其他模块:
#!/usr/bin/perl use strict; use warnings; use Math::Expression; my $env = Math::Expression->new; my $res = $env->Parse( '5+2-1' ); # my $res = $env->Parse( 'print you are hacked' ); # no math expression here print $env->Eval( $res );