Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I have worked a lot with changes of the symbol table for Safe::World, and looking in the replies that your node got, I think that none of them are the best way.
Well, say that my way is better is easy, soo I will show what happens in the 3 different types:
This will just remove all the entry from the table, but wont ensure that the sub reference was really removed from the memory. Making test of full deletion of packages for Safe::World, is easy to see that if you don't undef explicity a reference from the memory it will stay there even if you clean the HASH of the symbol table. But one of the problems here is that you remove all the references, soo, if you have a $foo and &foo, you will erase both.
Just make a undef to the &sub actually works, but you will still have a *foo{CODE} value in the GLOB, what will use memory. Note that undef is the standar way to do that, and is the recomended way, but you won't have the GLOB exactly as you have it before set the sub.
In Perl is impossible to create a GLOB that exists only in the scope. Soo, gensym() creates a new GLOB at Symbol::GENx, where x is a number. Soo, it won't be cleanned when you go out of the scope. Again you will be just duplicating everything.
Since a GLOB really need to be in the symbol table, local(*FOO) will create a GLOB that replaces the already existing GLOB in the symbol table for the given scope. Soo, after go out of the scope, the previous will be back. The biggest problem is when you make references to the local(*GLOB) after go out of the scope. Soo, if you make local(*FOO), and want to make something like a closure of it to $holder = \*FOO, it won't work. Also for recursion or loop codes, the last local(*FOO) will change the previous sets.
Is easy, we just create a holder for the different types inside the GLOB, make a undef, than reset the values, unless the removed type: This will print: Note that this approach is to remove a reference type of a GLOB. If you want to overwrite one of the types, the best is to just set the GLOB with a reference. Actually all of this depends of what you need. If you wan't speed, use just undef &FOO, but if you want to save memory I recomend the glob_rm() function. Enjoy! ;-P
Graciliano M. P. In reply to Re: undefining one slot of a typeglob
by gmpassos
|
|