Chinaunix首页 | 论坛 | 博客
  • 博客访问: 371149
  • 博文数量: 61
  • 博客积分: 2451
  • 博客等级: 上尉
  • 技术积分: 650
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-06 21:24
文章分类

全部博文(61)

文章存档

2012年(1)

2011年(44)

2010年(16)

分类: LINUX

2011-03-26 11:20:05

SYNOPSIS
       In module YourModule.pm:

         package YourModule;
         require Exporter;
         @ISA = qw(Exporter);
         @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request

       or

         package YourModule;
         use Exporter 'import'; # gives you Exporter's import() method directly
         @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request

       In other files which wish to use "YourModule":

         use YourModule qw(frobnicate);      # import listed symbols
         frobnicate ($left, $right)          # calls YourModule::frobnicate

       Take a look at "Good Practices" for some variants you will like to use
       in modern Perl code.


其他模块是通过Exporter 模块提供的import  方法来将自己的符号导出到current package 的 
当use Module;被执行时perl 会自动调用import method 导入相关符号
use Module;
将@EXPORT 中的所有符号的导入
相当于
 BEGIN { require Module; Module->import( LIST ); }
use Module qw(list);
导入list指定的符号,但这些必须在@EXPORT或@EXPORT_OK数组中的,不然会出错
use Module();
加载模块但是不导入符号相当于
BEGIN { require Module }

如果use module; 后面没加符号list的话 它将导出@EXPORT 数组中的符号。如果加了话 他将导入list指定的符号




阅读(1640) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~