解决方法
根据需要加载模块
@H_502_2@如果需要在运行时加载整个模块,则使用
require
.但是要导入,则需要额外的代码.这是一个例子:
@H_502_2@使用其功能时加载模块 @H_502_2@您还可以在use
- ## this function is almost the same
- ## as "use My::Module qw( :something )"
- sub load_big_module_at_runtime {
- ## load module in runtime
- require My::Module;
- ## do import explicty if you need it
- My::Module->import( ':something' );
- }
autouse
仅在使用其功能时加载模块.例如:
@H_502_2@仅在使用时加载功能 @H_502_2@还有
- ## will load module when you call O_EXCL()
- use autouse Fcntl => qw( O_EXCL() );
SelfLoader
模块,它允许您仅在需要时加载单个功能.看看AutoLoader
模块,它做了几乎相同的事情.
@H_502_2@我还建议从Perl Cookbook阅读相应的食谱.