为什么“使用”是“使用”?语句首先在 BEGIN 块中执行?
当我执行以下代码时,我得到Can't located SomePackage.pm in @INC ...
。
BEGIN {
die;
use SomePackage;
}
为什么use
先于die
执行?
When I execute the following code, I get Can't locate SomePackage.pm in @INC ...
.
BEGIN {
die;
use SomePackage;
}
Why is use
executed before die
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
use SomePackage
完全等同于BEGIN
代码块会尽快执行,即在它完全定义时执行。第二个BEGIN
(由use
隐含)首先被完全定义,因此首先被执行。use SomePackage
is exactly equivalent toA
BEGIN
code block is executed as soon as possible, that is, the moment it is completely defined. The secondBEGIN
(which is implied byuse
) is completely defined first, and is thus executed first.来自 http://perldoc.perl.org/functions/use.html
From http://perldoc.perl.org/functions/use.html