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
orgrep
) 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