在CORE :: GLOBAL中哪些Perl内置函数不能被覆盖?

perlsub文档的 Overriding Built-in Functions部分提供

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::.

然后给出几个例子.但是最后呢

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

什么是完整列表?

解决方法

toke.c中任何值为负的值都可以被覆盖;所有其他人可能不会.你可以看源码 here.

例如,我们来看看第10,396行的waitpid

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怎么样?

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

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

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

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...