免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4257 | 回复: 5
打印 上一主题 下一主题

引用模块的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-20 14:54 |只看该作者 |倒序浏览
请问,require 模块 和 use 模块有什么不同???

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2006-09-20 14:57 |只看该作者
为什么都不看文档呢?
  1. D:\MoChou>perldoc -f use
  2.     use Module VERSION LIST
  3.     use Module VERSION
  4.     use Module LIST
  5.     use Module
  6.     use VERSION
  7.             Imports some semantics into the current package from the named
  8.             module, generally by aliasing certain subroutine or variable
  9.             names into your package. It is exactly equivalent to

  10.                 BEGIN { require Module; import Module LIST; }

  11.             except that Module *must* be a bareword.
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-09-20 16:00 |只看该作者
bareword

论坛徽章:
0
4 [报告]
发表于 2006-09-20 16:01 |只看该作者
看不太明白!

论坛徽章:
0
5 [报告]
发表于 2006-09-20 18:57 |只看该作者
原帖由 herolyh 于 2006-9-20 14:54 发表
请问,require 模块 和 use 模块有什么不同???


use Module; 相当于

BEGIN {
    require Module;
    Module->import;
}

也就是说use的包,会把该包里默认export出的符号,import进当前包。

例如:

use CGI;
print param('submit');

这里的param()函数就是CGI.pm默认export出的了。

require不import进任何符合,如果你写成:

require CGI;
print param('submit');

会报错,因为param()函数没有import进来。

在效果上,require Module与use Module ()【注意这里有对'()'符号】一样的,不同的是前者在运行时执行,后者在编译时执行。

Hope this helps!

论坛徽章:
0
6 [报告]
发表于 2006-09-22 09:34 |只看该作者
谢谢版主!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP