in reply to Undefining symbol tables and globs and things, oh my

How does perl know how to find $Yakkity::Yak::a after the package's symbol table is gone?
Because you have a compile-time reference to the typeglob associated with a, in the code print "a = $Yakkity::Yak::a\n"; undeffing the symbol table just removes a ref to the typeglob; the typeglob itslef continues to exist. At run-time, perl ops do not lookup variables in stashes; instead the ops contain a pointer to the typeglob.

Dave.

Replies are listed 'Best First'.
Re^2: Undefining symbol tables and globs and things, oh my
by ikegami (Patriarch) on Aug 10, 2005 at 13:56 UTC

    To illustrate dave_the_m's and Bob9000's point, compare

    #!/usr/bin/perl $Yakkity::Yak::a = 42; print "a = $Yakkity::Yak::a\n"; print "Undeffing symbol table\n"; undef %Yakkity::Yak::; print "a = $Yakkity::Yak::a\n"; __END__ a = 42 Undeffing symbol table a = 42

    with

    #!/usr/bin/perl $Yakkity::Yak::a = 42; print "a = $Yakkity::Yak::a\n"; print "Undeffing symbol table\n"; undef %Yakkity::Yak::; print "a = ${'Yakkity::Yak::a'}\n"; # <- Hardcoded reference removed __END__ a = 42 Undeffing symbol table a =

    The last reference to $Yakkity::Yak::a keeps the symbol alive. If the reference to one built at run-time, the symbol disappears along with the table.

    Sorry, this post just explains what is seen, not how to work around it. Hopefully, someone has a solution.