如何在运行时在Perl中加载模块? [英] How do I load a module at runtime in Perl?

查看:78
本文介绍了如何在运行时在Perl中加载模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时在Perl中加载模块?我尝试了以下方法,但是没有用.我在程序中的某处写了以下内容:

Is it possible to load a module at runtime in Perl? I tried the following, but it didn't work. I wrote the following somewhere in the program:

require some_module;
import some_module ("some_func");
some_func;

推荐答案

Foo.pm

package Foo;

use strict;
use warnings;

use base qw(Exporter);
our @EXPORT = qw(bar);

sub bar { print "bar(@_)\n" }

1;

script.pl

use strict;
use warnings;

require Foo;
Foo->import('bar');
bar(1, 22, 333);

这篇关于如何在运行时在Perl中加载模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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