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.
Back to perlfaq7