gmpassos has asked for the wisdom of the Perl Monks concerning the following question:
I have a package FOO, where inside works a Safe compartment (from Safe.pm), and FOO need to be cleaned to be reused. All the stufs to make this need to be pure Perl and need to work from Perl 5.6.0+!
To do that I used Devel::Symdump to get the symbols table and created this function:
There is a better way or module to do that?!use Devel::Symdump ; my %clean_types = ( 'packages' => '::' , 'scalars' => '$' , 'arrays' => '@' , 'hashes' => '%' , 'functions' => '&' , 'ios' => '*' , ) ; my @clean_order = qw(scalars arrays hashes functions ios packages) ; sub clean_pack { my ( $pack ) = @_ ; my $dump = Devel::Symdump->rnew($pack); my %glob ; foreach my $i ( @clean_order ) { my $type = $clean_types{$i} ; my @symbols = $dump->$i ; foreach my $name ( @symbols ) { #print "$type$name\n" ; if ($type eq '\$') { undef $$name ;} elsif ($type eq '\@') { undef @$name ;} elsif ($type eq '\%') { undef %$name ;} elsif ($type eq '\&') { undef &$name ;} elsif ($type eq '\*') { undef *$name ;} elsif ($type eq '::') { $glob{"$name\::"} = 1 ;} $glob{$name} = 1 ; } } foreach my $Key ( reverse sort keys %glob ) { undef *$Key ;} }
I really need to reuse the package to run the Safe compartment again! 1- because I need to clean the memory, 2- because I can't use a different name for the package.
My method works fine, but I think that Perl don't clean 100% of the memory! It cleans all the variables, functions, *ios and packages, but some bytes are still in use!
Graciliano M. P.
"The creativity is the expression of the liberty".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: better way to cleanup a package?
by shotgunefx (Parson) on Dec 03, 2002 at 08:59 UTC | |
by gmpassos (Priest) on Dec 03, 2002 at 19:27 UTC | |
by shotgunefx (Parson) on Dec 04, 2002 at 01:50 UTC | |
|
Re: better way to cleanup a package?
by djantzen (Priest) on Dec 03, 2002 at 07:26 UTC | |
|
Re: better way to cleanup a package?
by Courage (Parson) on Dec 03, 2002 at 07:59 UTC | |
|
Re: better way to cleanup a package?
by adrianh (Chancellor) on Dec 04, 2002 at 12:21 UTC |