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

Not understanding deleted symbol key access

Thread Next
From:
Linux Expert
Date:
April 15, 2010 08:57
Subject:
Not understanding deleted symbol key access
Message ID:
n2q5e4977921004150857k820e1fe0x82220159d555ed90@mail.gmail.com
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";

--output--
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About