加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么Perl中的“import”子例程不是大写的

发布时间:2020-12-15 21:43:30 所属栏目:大数据 来源:网络整理
导读:我好奇.大多数Perl隐式调用的子例程必须以全部大写字母命名. TIESCALAR,DESTROY等.事实上 perldoc perltoot 说 If constructors can have arbitrary names,then why not destructors? Because while a constructor is explicitly called,a destructor is not
我好奇.大多数Perl隐式调用的子例程必须以全部大写字母命名. TIESCALAR,DESTROY等.事实上 perldoc perltoot

If constructors can have arbitrary
names,then why not destructors?
Because while a constructor is
explicitly called,a destructor is
not. Destruction happens
automatically via Perl’s garbage
collection (GC) system,which is a
quick but somewhat lazy
reference-based GC system. To know
what to call,Perl insists that the
destructor be named DESTROY. Perl’s
notion of the right time to call a
destructor is not well-defined
currently,which is why your
destructors should not rely on when
they are called.

Why is DESTROY in all caps? Perl on
occasion uses purely uppercase
function names as a convention to
indicate that the function will be
automatically called by Perl in some
way. Others that are called
implicitly include BEGIN,END,
AUTOLOAD,plus all methods used by
tied objects,described in perltie.

那么为什么导入子程序是小写的呢?有没有人对此有很好的了解?

解决方法

为了扩展DVK的答案,有些情况下您可以合法地明确调用导入,例如在加载可选模块或自动填充名称空间时:
eval "require $modulename; $modulename->import( LIST ); ";

我想不出任何你想要明确调用DESTROY,TIESCALAR等的情况.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读