哪些 Perl 内置函数不能在 CORE::GLOBAL 中被覆盖? [英] Which Perl built-ins cannot be overridden in CORE::GLOBAL?

查看:25
本文介绍了哪些 Perl 内置函数不能在 CORE::GLOBAL 中被覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

覆盖内置函数部分perlsub 文档提供

The Overriding Built-in Functions section of the perlsub documentation provides

当您希望在任何地方覆盖内置函数而不考虑名称空间边界时,有时还可以使用第二种方法.这是通过将子导入特殊命名空间 CORE::GLOBAL:: 来实现的.

There is a second method that is sometimes applicable when you wish to override a built-in everywhere, without regard to namespace boundaries. This is achieved by importing a sub into the special namespace CORE::GLOBAL::.

然后举几个例子.然而,最后是

and then gives a few examples. At the end, however, is

最后,一些内置函数(e.g. existsgrep)不能被覆盖.

Finally, some built-ins (e.g. exists or grep) can't be overridden.

完整列表是什么?

推荐答案

toke.c 中的任何负值都可以被覆盖;所有其他人可能不会.您可以在此处查看源代码.

Any value that is negative in toke.c can be overridden; all others may not. You can look at the source code here.

例如,让我们看看 waitpid 在第 10,396 行:

For example, let's look at waitpid on line 10,396:

    case 'w':
      if (name[1] == 'a' &&
          name[2] == 'i' &&
          name[3] == 't' &&
          name[4] == 'p' &&
          name[5] == 'i' &&
          name[6] == 'd')
      {                                       /* waitpid    */
        return -KEY_waitpid;
      }

由于 waitpid 是负数,它可能会被覆盖.grep 怎么样?

Since waitpid is negative, it may be overridden. How about grep?

        case 'r':
          if (name[2] == 'e' &&
              name[3] == 'p')
          {                                   /* grep       */
            return KEY_grep;
          }

它是肯定的,所以它不能被覆盖.这意味着不能覆盖以下关键字:

It's positive, so it cannot be overridden. That means that the following keywords cannot be overridden:

chop、defined、delete、do、dump、each、else、elsif、eval、exists、for、foreach、format、glob、goto、grep、if、keys、last、local、m、map、我的、下一个、不、包、弹出、pos、打印、printf、原型、推送、q、qq、qw、qx、重做、返回、s、标量、移位、排序、拼接、拆分、研究、子、领带,绑定,tr,undef,除非,unshift,解开,untie,使用,while,y

这篇关于哪些 Perl 内置函数不能在 CORE::GLOBAL 中被覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆