Submitted on: 7/29/2000 10:59:50 PM By: Found on the World Wide Web
Level: Intermediate User Rating:
By 1 Users Compatibility:5.0 (all versions), 4.0 (all versions)
Users have accessed this article 3304 times.
How do I clear a package?
Use this code, provided by Mark-Jason Dominus:
sub scrub_package {
no strict 'refs';
my $pack = shift;
die "Shouldn't delete main package"
if $pack eq "" || $pack eq "main";
my $stash = *{$pack . '::'}{HASH};
my $name;
foreach $name (keys %$stash) {
my $fullname = $pack . '::' . $name;
# Get rid of everything with that name.
undef $$fullname;
undef @$fullname;
undef %$fullname;
undef &$fullname;
undef *$fullname;
}
}
Or, if you're using a recent release of Perl, you can just use the
Symbol::delete_package() function instead.