in reply to Re: What delete from symbol table really means? (Deleting typeglob of a specified package)
in thread What delete from symbol table really means? (Deleting typeglob of a specified package)

Though I have to admit that it's a bit confusing that a typeglob keeps track of it's original package and name, even after it isn't listed there anymore.

lanx@lanx-1005HA:~/pm$ cat tst_glob.pl $\="\n"; $n=123; $gr=\*n; print *n{PACKAGE}," :: ",*n{NAME}," = ", ${*n{SCALAR}}; delete $main::{n}; print *{$gr}{PACKAGE}," :: ",*{$gr}{NAME}," = ", ${*{$gr}{SCALAR}}; lanx@lanx-1005HA:~/pm$ perl tst_glob.pl main :: n = 123 main :: n = 123

Cheers Rolf

PS: Je suis Charlie!

  • Comment on Re^2: What delete from symbol table really means? (Deleting typeglob of a specified package)
  • Download Code

Replies are listed 'Best First'.
Re^3: What delete from symbol table really means? Symbol::delete_package
by Anonymous Monk on Feb 16, 2015 at 19:28 UTC
    see Symbol Symbol::delete_package
    # # of Safe.pm lineage # sub delete_package ($) { my $pkg = shift; # expand to full symbol table name if needed unless ($pkg =~ /^main::.*::$/) { $pkg = "main$pkg" if $pkg =~ /^::/; $pkg = "main::$pkg" unless $pkg =~ /^main::/; $pkg .= '::' unless $pkg =~ /::$/; } my($stem, $leaf) = $pkg =~ m/(.*::)(\w+::)$/; my $stem_symtab = *{$stem}{HASH}; return unless defined $stem_symtab and exists $stem_symtab->{$leaf +}; # free all the symbols in the package my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; foreach my $name (keys %$leaf_symtab) { undef *{$pkg . $name}; } # delete the symbol table %$leaf_symtab = (); delete $stem_symtab->{$leaf}; }
      See what? I have no idea what the pasted code is supposed to prove.

      Please take advantage of preview before posting code.

      BTW: see also Re^2: dumping lexical filehandles (not in STASH), showing that the slots PACKAGE and NAME are sometimes wrongly set in Perl (lexicals have no package)

      Cheers Rolf

      PS: Je suis Charlie!