in reply to What delete from symbol table really means? (Deleting typeglob of a specified package)
You only deleted a stash entry pointing to the glob, not the glob which continues to exist as long as it is referenced in code.
A 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.
globs and stashes are confusing, I tried to translate what is happening to HoHs.
Maybe that makes it clearer
BEGIN { # at compile time %stash =(); # 'package stash' $stash{n}{SCALAR} =undef; # $n first use ( i.e. our-declaration ) $n_glob = $stash{n}; # exists only hardcoded } # at runtime: execute compiled op-codes $n_glob->{SCALAR}=123; delete $stash{n}; print $n_glob->{SCALAR}; # > 123
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') .
¹)
DB<104> $n=123 => 123 DB<105> *n{SCALAR} => \123
²) i.e. refs to SCALAR, ARRAY, HASH, CODE, IO, GLOB, FORMAT see perlref
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What delete from symbol table really means? (Deleting typeglob of a specified package)
by LanX (Saint) on Feb 16, 2015 at 18:06 UTC | |
by Anonymous Monk on Feb 16, 2015 at 19:28 UTC | |
by LanX (Saint) on Feb 16, 2015 at 19:42 UTC |