develooper Front page | perl.beginners | Postings from April 2010

Not understanding deleted symbol key access

Thread Next
Linux Expert
April 15, 2010 08:57
Not understanding deleted symbol key access
Message ID:
I'm following an example in "Mastering Perl" pg 130.  He demonstrates
setting package variables $m and $n and displays their contents as well as
their keys held in the symbol table.  He then proceeds to delete the symbol
table keys for said variables, yet they still somehow hold their value.
 What I don't understand is how the variable continues to exist if it's
entry is removed from the symbol table.

Here's a simplified example to demonstrate:

package Foo;
$n = 10;

print "$_ " foreach keys %{Foo::};
print "\nBefore: $n\n";

delete $Foo::{'n'};

print "$_ " foreach keys %{Foo::};
print "\nAfter:  $n\n";

Before: 10

After:  10

Notice we see that 'n' is a key in the symbol table, and rightfully prints
it's value as 10.  Then after deleting from the symbol table, it doesn't
show up anymore in the symbol table, yet it's value is still 10.  How does
this work?

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About