使用eval加载模块 [英] Use of eval to load modules

查看:152
本文介绍了使用eval加载模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Perl和内置函数 eval 时遇到了麻烦. 我环顾了网上,但找不到任何答案或示例代码.

I'm facing some trouble with Perl and built-in function eval. I have looked around the web but I can't find any answer or sample code.

我想动态加载模块(在执行之前我不知道它们)

I'd like to load modules dynamically (I don't know them before the execution time)

$module_name="Auth_Auth_Test";
my $ret1;
ret = eval{
     "use ".$module_name;
     $ret1 = $module_name."::test(".$log.")";
};              
$log->debug ($@) if $@;
$log->debug ("Ret".$ret1);

返回是:

RetAuth_Auth_Test :: test(自定义:: Log = HASH(0x1194468))

RetAuth_Auth_Test::test(Custom::Log=HASH(0x1194468))

以下方法对我有用,但我无法使用相同的子例程加载多个模块:

The following method worked for me but I can't load more than one module with same subroutine :

my $use = "use ".$module_name." qw(&test)";
$ret = eval $use;

# Debug for eval
$log->debug ($@) if $@;

$ret = test($log);

谢谢您的帮助

推荐答案

使用 Module :: Load .

这篇关于使用eval加载模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆