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

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

问题描述

perlsub文档提供了

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

有第二种方法有时适用于您希望在任何地方覆盖内置对象而又不考虑名称空间边界的情况.这是通过将子项导入特殊名称空间CORE::GLOBAL::来实现的.

,然后给出一些示例.最后是

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

最后,某些内置代码(例如 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 第10396行:

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, my, next, no, package, pop, pos, print, printf, prototype, push, q, qq, qw, qx, redo, return, s, scalar, shift, sort, splice, split, study, sub, tie, tied, tr, undef, unless, unshift, untie, until, use, while, y

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

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