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

标签 perl naming-conventions implicit

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

相关文章:

正则表达式不适用于 Perl 中的特定特殊字符

perl - 从带有 header 的 tsv 文件加载 PDL 矩阵无法按预期工作

c++ - C++ 中变量、方法等的良好命名约定是什么?

scala - 案例类和同伴的不同顺序的隐式解析

c# - 收到错误 "No best type found for implicitly-typed array"

scala - Scala 2.12 中的隐式 ExecutionContext 优先级

perl - 为什么 Perl 的 Class::XSAccessor 找不到 Array.so?

perl 确定 URL SSL 证书 key 长度

sql - 外键的命名约定

javascript - 属性和方法名称的下划线前缀仅仅是一种约定吗?