perl - Perl 中以下划线开头的子程序名称

标签 perl

这是来自 Markdown 源的示例:

sub _StripLinkDefinitions{ somecode }

这是什么意思?它只是一种约定还是语言的一部分?

最佳答案

这是一个约定,记录在 perlstyle 中:

You can use a leading underscore to indicate that a variable or function should not be used outside the package that defined it.

另外,在 Perl best practices第 49 页,说:

Prefix “for internal use only” subroutines with an underscore.

附上解释:

A utility subroutine exists only to simplify the implementation of a module or class. It is never supposed to be exported from its module, nor ever to be used in client code.

Always use an underscore as the first “letter” of any utility subroutine’s name. A leading underscore is ugly and unusual and reserved (by ancient C/Unix convention) for non-public components of a system. The presence of a leading underscore in a subroutine call makes it immediately obvious when part of the implementation has been mistaken for part of the interface.

相关:下划线也有特殊含义,作为语言的一部分 - 例如:

  • 变量 what's name 只是下划线,(检查 perlvar )- 例如:
    • $_ - 默认输入和模式搜索空间。
    • @_ - 所有子例程参数的列表
    • _ - 特殊文件处理缓存来自最后一个stat或文件测试运算符(例如-f)的信息
  • 语言结构以双下划线开头和结尾,例如:__DATA____END____FILE____PACKAGE__, __LINE__

关于perl - Perl 中以下划线开头的子程序名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29525465/

相关文章:

php - 将多个 csv 文件组合在一起,并在连接期间添加一列

perl - 如何在 Perl 中以编程方式发现 Win32::OLE 对象的属性和方法?

regex - 删除前导零但不是全零

perl - 如何从 Perl 快速访问许多大型 CSV 文件中的数据?

perl - 将变量传递给 Mojolicious 中的布局模板

regex - 如何在 Perl 的匹配正则表达式中包含一个变量,并检查该变量是否不在字符串中?

php - 如何从 Perl 调用 PHP 脚本?

dbi - [perl]如何强制perl在我自己的路径中使用模块?

perl - 在 Perl 中,您如何动态选择要用作回调的方法?

sql - PostgreSQL - 插入包含数组的复合类型数组