Help to manage temporary files/dirs
use Arch::TempFiles qw(temp_file_name temp_file temp_dir); # all will be removed automatically on the script completion my $file_name1 = temp_file(); my $file_name2 = temp_file_name("status"); my $dir_name = temp_dir("arch-tree"); use Arch::TempFiles; my $tmp = new Arch::TempFiles; $tmp->root($tmp->dir); my $file_name = $tmp->name; open OUT, ">$file_name"; close OUT;
This module deals with temporary file names. It is similar to File::Temp, but simplier and more focused. Also, File::Temp is relatively new and was not shipped with older perl versions.
Both function interface and object oriented interface are supported.
The following functions are available:
temp_root, temp_name, temp_file_name, temp_dir_name, temp_file, temp_dir.
The corresponding class methods are available too:
root, name, file_name, dir_name, file, dir.
Change or return the root of the temporary files and dirs. The default is either $ENV{\s-1TMP_DIR\s0} or \*(L"/tmp\*(R".
Return the unused temporary file name. The default file name is \*(L"/tmp/,,arch-XXXXXX\*(R" where \s-1XXXXXX\s0 is a random number. To change this name use \*(C`temp_root\*(C' and/or provide label that replaces \*(L"arch\*(R". Please note, that the operation of acquiring the file name using this function/method and actual creating of this file is not atomic. So you may need to call this method again if the creation is failed, for example if some other process created the same file in the middle.
Like \*(C`temp_name\*(C', but stores the name in the file list that will be removed on the end (on object destruction).
Like \*(C`temp_name\*(C', but stores the name in the dir list that will be removed on the end (on object destruction).
Like \*(C`temp_file_name\*(C', but also creates the file.
Like \*(C`temp_dir_name\*(C', but also creates the dir.
Awaiting for your reports.
Mikhael Goikhman ([email protected]\*(--Perl-GPL/arch-perl\*(--devel).
For a different interface, see File::Temp.