Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
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!#!/usr/bin/perl package Foo { $n = 10; show_foo( "After assignment" ); delete $Foo::{'n'}; show_foo( "After delete" ); sub show_foo { print "-" x 10, $_[0], "-" x 10, "\n"; print "\$n is $n\n"; foreach my $name ( keys %Foo:: ) { print "$name\n"; } } }#end of package Foo ##OUT ----------After assignment---------- $n is 10 show_foo n ----------After delete---------- $n is 10 show_foo
and$n = 123; delete $::{n}; eval '$n=456'; print $n; eval 'print $n'; #OUT 123456
So there is a way to safely access and modify (so delete too) a specified entry in the symbol table or a specified slot in it (using the so called *foo{THING} notation). There is a gently way? or I need to nuke the package at whole? as in:$n = 123; sub get_n { $n } BEGIN { delete $::{n} } $n = 456; print get_n(); print $n; #OUT 123456
#!/usr/bin/perl use Symbol qw(delete_package); package Foo { $n = 10; show_foo( "After assignment" ); sub show_foo { print "-" x 10, $_[0], "-" x 10, "\n"; print "\$n is $n\n"; foreach my $name ( keys %Foo:: ) { print "$name\n"; } } }#end of package Foo delete_package('Foo'); # package Foo again package Foo{ show_foo( "After delete" ); } #OUT ----------After assignment---------- $n is 10 show_foo n Undefined subroutine & called at ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What delete from symbol table really means? (Deleting typeglob of a specified package)
by LanX (Saint) on Feb 16, 2015 at 14:25 UTC | |
by LanX (Saint) on Feb 16, 2015 at 18:06 UTC | |
by Anonymous Monk on Feb 16, 2015 at 19:28 UTC | |
by LanX (Saint) on Feb 16, 2015 at 19:42 UTC | |
Re: What delete from symbol table really means? (Deleting typeglob of a specified package)
by Anonymous Monk on Feb 16, 2015 at 10:54 UTC | |
Re: What delete from symbol table really means? (Deleting typeglob of a specified package)
by Anonymous Monk on Feb 16, 2015 at 13:28 UTC |