I'd swear I've asked this question, but since I can't find the post, here's hoping I didn't :)
Basically, deleting subroutines from a symbol table seems a bit buggy, but I don't know if this behavior is documented or not.
#!/usr/bin/perl -l sub this { 'this' } print this; undef &main::this; # undefine the code slot print main->can('this') ? 'main->can("this")' : '! main->can("this")'; eval {print this}; print $@; undef *main::this; # undefine the entire glob print main->can('this') ? 'main->can("this")' : '! main->can("this")'; __END__ # result this main->can("this") Undefined subroutine &main::this called at sub.pl line 7. ! main->can("this")
The first time I try to remove the subroutine via undef it still leaves a CODE slot in the symbol table's *this glob. I can't just use delete because it's not an array or a hash (it fails if you try). This is bad in procedural code but it's awful in OO code because $object->can('this') will succeed even if the method has been deleted.
This leaves me with having to undefine the entire glob but that's a horrible solution because the other slots in the glob, if any, are blown away. Is this a known/documented bug/feature in Perl? Is there a workaround?
Cheers,
Ovid
New address of my CGI Course.
In reply to Removing subroutines from symbol tables by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |