为什么 LWP::UserAgent 是通过 require LWP::UserAgent 导入的,而不是 use LWP::UserAgent?
我对这种语言还很陌生,但我之前一直使用 use
导入特定模块,
为什么 LWP::UserAgent
使用 require
执行来自 perldoc LWP::UserAgent
的工作:
require LWP::UserAgent;
I'm pretty new to this language but I've been using use
to import a specific module before,
why LWP::UserAgent
uses require
to do the job as from perldoc LWP::UserAgent
:
require LWP::UserAgent;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与
如果
require LWP::UserAgent;
可接受,则表明import
对 LWP::UserAgent 没有任何作用。也许文档使用require
的目的是巧妙地暗示这一点?require LWP::UserAgent;
和use LWP::UserAgent;
之间的唯一区别在于require
的执行时间。对于前者,它发生在整个文件编译之后。对于后者,一旦该语句被编译,它就会发生。实际上,面向对象的模块没有太大区别。就我个人而言,我使用
That's the same 与
That way,我保证不会导入任何我不想要的东西,并且我使用我用于其他模块的熟悉的
use
。需要
使用
is the same as
If
require LWP::UserAgent;
is acceptable, that goes to show thatimport
does nothing for LWP::UserAgent. Maybe the point of the documentation's use ofrequire
is to subtly imply this?The only difference between
require LWP::UserAgent;
anduse LWP::UserAgent;
is thus whenrequire
is executed. For the former, it happens after the entire file has been compiled. For the latter, it occurs as soon as that statement has been compiled. In practical terms, there's no much difference for object-oriented modules.Personally, I use
That's the same as
That way, I'm guaranteed not to import anything I don't want, and I use the familiar
use
I use for other modules.require
use
require Module::Name
与use
具有相同的效果,仅在运行时,而不是编译时。当您想有条件地需要一个模块时,这有时是有利的。我认为文档没有任何特殊原因说require
而不是use
。require Module::Name
has the same effect asuse
, only at run-time, not compile-time. This is sometimes advantageous when you want to conditionally require a module. I don't think there's any particular reason for the doc to sayrequire
instead ofuse
.对于来自谷歌搜索并寻找此解决方案的人:
对于 Message Error: LWP::UserAgent not found at ./apache_accesses line 86。
解决方案:
apt-get 安装 libwww-perl
For people who come from google search and looking this solutions:
For Message Error: LWP::UserAgent not found at ./apache_accesses line 86.
Solution:
apt-get install libwww-perl