Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: undefining one slot of a typeglob

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


in reply to Re: undefining one slot of a typeglob
in thread undefining one slot of a typeglob

it didn't occur to me that i didn't have to use a typeglob as my holder. good idea, and although it's a core module, this approach means i have one less use statement. Can anybody tell me why do this:
if ($type eq 'SCALAR') { undef ${*{$glob}} ;} elsif ($type eq 'ARRAY') { undef @{*{$glob}} ;} elsif ($type eq 'HASH') { undef %{*{$glob}} ;} elsif ($type eq 'CODE') { undef &{*{$glob}} ;} elsif ($type eq 'IO') { close *{$glob} ;}
instead of this:
($type eq 'IO') ? close *{$glob} : undef *{$glob}{$type};
and i have to wonder if just using this would not work:
undef *{$glob}{$type};
update: I should note that completely eradicating the sub from memory isn't necessarily the problem here, as sometimes the created CODE glob is simply an alias from another package rather than a brand new anonymous sub.

Replies are listed 'Best First'.
Re: Re: Re: undefining one slot of a typeglob
by gmpassos (Priest) on Feb 24, 2004 at 08:24 UTC
    If I'm not wrong we can't change a glob key/element, only access it. Soo, this won't work:
    undef *{$glob}{$type} ;
    And I make this:
    if ($type eq 'SCALAR') { undef ${*{$glob}} ;} elsif ($type eq 'ARRAY') { undef @{*{$glob}} ;} elsif ($type eq 'HASH') { undef %{*{$glob}} ;} elsif ($type eq 'CODE') { undef &{*{$glob}} ;} elsif ($type eq 'IO') { close *{$glob} ;}
    Not to remove the element from the GLOB, but to ensure that it goes out of the memory, since undef *{$glob} already remove all the keys/elements. Actually for your needs you can remove all the if ( $type eq '...' ).

    Graciliano M. P.
    "Creativity is the expression of the liberty".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-03-29 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found