This is a follow up on the discussion in keys %::. Since the "package Foo;" statement introduces an entry in the main symbol table $::{'Foo::'} as well as its typeglobed value %Foo::, it seems that if I delete this entry explicitly, then one should not be able to do "Foo->new()", and the Foo symbol table should be gone also. The following code confirms the first, but it seems the %Foo:: still exists, why is that?
# test.pl use strict; package Foo; sub new{ return bless {}, shift; } sub foo{ my $self = shift; print "Foo called\n"; } package main; # print the full symbol table, notice the Foo:: entry print "$_ => $::{$_}\n" foreach keys %::; print "\n\n"; delete $::{'Foo::'}; # shouldn't this delete the symbol table for Foo? # print again the full symbol table, notice Foo:: is gone. print "$_ => $::{$_}\n" foreach keys %::; print "\n\n"; # seems still there. print "$_ => $Foo::{$_}\n" foreach keys %Foo::; print "\n\n"; # but can't call the following, as expected my $f = new Foo(); $f->foo();
On cywin, the result is (removed some entries to make it shorter):
" => *main::" CORE:: => *main::CORE:: strict:: => *main::strict:: $ => *main::$ Foo:: => *main::Foo:: main:: => *main::main:: => *main:: @ => *main::@ <none>:: => *main::<none>:: " => *main::" CORE:: => *main::CORE:: strict:: => *main::strict:: $ => *main::$ main:: => *main::main:: => *main:: @ => *main::@ <none>:: => *main::<none>:: foo => *Foo::foo new => *Foo::new Can't locate object method "new" via package "Foo" (perhaps you forgot + to load " Foo"?) at test.pl line 30.

In reply to Directly remove an entry from the symbol table by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.