Think about Loose Coupling | |
PerlMonks |
Re: What delete from symbol table really means? (Deleting typeglob of a specified package)by LanX (Saint) |
on Feb 16, 2015 at 14:25 UTC ( [id://1116871]=note: print w/replies, xml ) | Need Help?? |
shortYou only deleted a stash entry pointing to the glob, not the glob which continues to exist as long as it is referenced in code.
longA typeglob is a kind of hash with 6 fixed slots holding different data types² ! The scalar $n is the value referenced in the scalar slot of of the glob *n ¹ Think of a stash as a HoH $pck{globname}{SCALAR} = \ 'value' And like all Perl data *n is a C structure somewhere in memory and can be retrieved by its reference GLOBREF = \*n. A symbol table is a hash holding names and references of such typeglobs. Eg in your case %Foo:: = ( ..., "n"=> GLOBREF, ... ) The code print $n internally compiles to something like print GLOBREF->{SCALAR} where GLOBREF was looked up in the stash at compile time and hardcoded into the OP-codes.
simplified analogyglobs and stashes are confusing, I tried to translate what is happening to HoHs. Maybe that makes it clearer
So deleting the Stash entry didn't delete the underlying glob (it's still referenced) Update: You only sabotaged introspection at run time or further compilations with eval('print $n') .
update¹)
²) i.e. refs to SCALAR, ARRAY, HASH, CODE, IO, GLOB, FORMAT see perlref
In Section
Seekers of Perl Wisdom
|
|