Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: undefining one slot of a typeglob

by AidanLee (Chaplain)
on Feb 24, 2004 at 03:45 UTC ( [id://331295]=note: print w/replies, xml ) Need Help??


in reply to undefining one slot of a typeglob

well, i am not afforded the luxury of limiting the scope of my symbol table manipulations, and for some reason, doing an undef &$foo works in that it destroys the subroutine, but UNIVERSAL::can($package,$method) still returns true, so something wasn't complete there. However, I now have code that does what i need and passes my tests:
use Symbol qw( gensym ); my $old; { no strict 'refs'; $old = \*{ "package::func_name" }; } my $new = gensym; *$new = *$old{$_} foreach ( grep { defined *$old{$_} } qw( SCALAR ARRA +Y HASH IO FORMAT ) ); { no strict 'refs'; *{ "package::func_name" } = *$new; }

Edit by tye, change PRE to CODE

Replies are listed 'Best First'.
Re: Re: undefining one slot of a typeglob
by ysth (Canon) on Feb 24, 2004 at 15:59 UTC
    Just a warning: *foo{FORMAT} isn't available before 5.8.0, so the above code will silently remove formats.
      good to know, but i'm honestly not too concerned about it. I included it for completeness, but to be honest i expect most globs going through this process of mine will only have a subref in it anyway.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://331295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-28 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found