in reply to Re: Automatically deleting selected directories on program exit
in thread Automatically deleting selected directories on program exit
Thanks merlyn. With my inherited legacy code, I'd prefer not to change the existing interface. And the directories to be deleted are not "temporary" but are supplied by the caller with specific names (so I can't see any way of using File::Temp directly). However, looking at the File::Temp implementation of _deferred_unlink() has allowed me to simplify the implementation as follows:
package MyTemp; use strict; use warnings; use File::Path (); my @dirs_to_delete; sub delete_on_close { push(@dirs_to_delete, @_) } END { print "Deleting dirs:\n"; print " $_\n" for @dirs_to_delete; File::Path::rmtree(\@dirs_to_delete); } 1;
|
|---|