gpt4 book ai didi

perl - 为什么 "import"子程序在 Perl 中没有大写

转载 作者:行者123 更新时间:2023-12-04 14:05:59 24 4
gpt4 key购买 nike

我好奇。大多数 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.



那么为什么是 import子程序左为小写?有没有人对此有很好的见解?

最佳答案

我会说“import ”没有被隐式调用。这是由 use 的实现发出的显式调用.引自 perldoc use :

It is exactly equivalent to:

BEGIN { require Module; Module->import( LIST ); }

关于perl - 为什么 "import"子程序在 Perl 中没有大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5051904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com