The main question is: why this $n is still here with his well round value? The entry in the symbol table is gone the variable itself no!
It seems you think that the notation $n is a shorthand for something like $symbol_table_hash{n}. You're used to how Perl's hashes work. But, as you see, symbol tables are special, they're used at compile time and at run time Perl doesn't even look if key n is present in the symbol table (if it can avoid that). Why? For efficiency, of course. Perl COULD always look up things in symbol tables, in principle (at least I don't see why it couldn't). But it would be slower.

Also, the value 10 is not "inside" the symbol table hash. 10 is just somewhere in computer memory; the symbol table has information about how to find 10 (has the address of 10). Perl uses that information (the address) when it's compiling the code. When the code runs, the address is "compiled into" show_foo, and show_foo uses it directly, without fetching it from the symbol table.

That answer contains others choking examples about the matter:
$n = 123; delete $::{n}; eval '$n=456'; print $n; eval 'print $n';
Think of it this way: Perl only looks up the symbol table at run time if it must. So, for example, when you eval a string, Perl has to consult the symbol table, because at compile time 'print $n' was just a string, not code. OTOH, print $n (without quotes) was code, so the compiler could figure it out, and replace $n with its direct address in memory.

use feature 'say'; package Foo { our $n = 10; show_foo("After assignment"); delete $Foo::{'n'}; show_foo("After delete"); sub show_foo { say shift; say '$n => ', $n; say '$Foo::n => ', $Foo::n; say '$Foo::{n} => ', $Foo::{n}; say; } }

Output:
$n => 10 $Foo::n => 10 $Foo::{n} => *Foo::n After delete $n => 10 $Foo::n => 10 $Foo::{n} =>
As you can see, it does remove the typeglob, it's just that 10 is untouched, and show_foo still knows where it is. $n and $Foo::n are special and resolved when compiling show_foo.

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

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.