Juerd has asked for the wisdom of the Perl Monks concerning the following question:
To allow dirty code to be evaluated in one of my scripts, I put them in uniquely named packages. However, badly written ad they are, they use package globals, and I'd like to get rid of them after script execution.
undef can undef scalars and destroy arrays, hashes, subs and even complete typeglobs, but it can't destroy packages.
Currently, I iterate over keys %{$package . '::'}, but if there's a better way to do it, I'd like to know about it.
sub cleanup { my ($package) = @_ undef *{$package . '::' . $_} for keys %{$package . '::'}; }
U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: undef Package;
by thpfft (Chaplain) on Apr 03, 2002 at 15:36 UTC | |
by Juerd (Abbot) on Apr 03, 2002 at 16:17 UTC | |
|
Re: undef Package;
by Fletch (Bishop) on Apr 03, 2002 at 13:36 UTC | |
|
Re: undef Package;
by Anarion (Hermit) on Apr 03, 2002 at 11:49 UTC | |
by Juerd (Abbot) on Apr 03, 2002 at 11:59 UTC | |
|
Re: undef Package;
by ariels (Curate) on Apr 03, 2002 at 11:40 UTC | |
by Juerd (Abbot) on Apr 03, 2002 at 11:46 UTC | |
|
Re: undef Package;
by premchai21 (Curate) on Apr 03, 2002 at 17:58 UTC |