develooper Front page | perl.perl5.porters | Postings from March 2003

undefining an active subroutine

Stas Bekman
March 17, 2003 23:24
undefining an active subroutine
Message ID:
It's interesting that one can redefine an active subroutine, but can't 
undefine it. The following code:

   sub redefine { *main::redefine = sub {};}
   sub undefine { undef &main::undefine;   }


   Subroutine main::redefine redefined at /tmp/undef line 5.
   Can't undef active subroutine at /tmp/undef line 9.

How redefining of an active sub is different from undefining it? Won't it be 
possible to assign a NOP, so it'd emulate redefining to a NOP?

I've noticed this while trying to avoid the 'redefine' subroutine warnings on 
older perls where the pragma 'warnings' is not available. So I thought I could 
undef it first and then re-assign. But that didn't work ;)

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide ---> Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About