我的 Perl 程序可以执行数据库中存储的代码吗?
是否可以将一些 Perl 代码保存在数据库中,使用 select
语句检索它,然后执行该 Perl 代码?
我尝试过使用 eval,但这似乎不起作用。
这是我现在正在尝试的,但它似乎不起作用:
my $temp = $qryResults[0];
print $temp . "\n";
eval{"$temp"};
输出是 $con->Disconnect();exit;
Is it possible to save some Perl code in a database, retrieve it using a select
statement, and execute that Perl code?
I have tried using eval, but that doesn't seem to work.
Here is what I'm trying right now and it doesn't seem to work:
my $temp = $qryResults[0];
print $temp . "\n";
eval{"$temp"};
The output is $con->Disconnect();exit;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需要:
您的版本不起作用的原因是由于 eval 的块形式对其进行评估,就好像您编写了一个简单的字符串一样:
这就像编写这行 Perl:
它不是代码;它是代码。这是一个字符串。
块形式评估块内的内容。如果字符串位于块内,则它只是一个字符串,而不是脚本。
字符串形式评估字符串内部的内容。
You just need:
The reason your version didn't work was due to the block form of eval evaluating it as if you had written a simple string:
It is like writing this line of Perl:
It isn't code; it's a string.
The block form evaluates what is inside the block. If a string is inside the block, it's just a string, not a script.
The string form evaluates what is inside the string.
我想通了;如果我删除大括号,那么它就可以工作。
I figured it out; if I remove the curly brackets then it works.