tempdir#

Create a uniquely named temporary directory and return its path.

Σύνοψη#

my $dir = tempdir();
my $dir = tempdir($template, DIR => $parent, CLEANUP => 1);
my $dir = tempdir(CLEANUP => 1);

Τι επιστρέφεται#

A plain string - the full path of the new directory, created with mode 0700. The directory is not removed automatically unless CLEANUP => 1 is passed.

Options#

  • DIR => $parent - parent directory for the new temp dir.

  • TMPDIR => 1 - place the directory under the system temp dir.

  • TEMPLATE => $t - template with at least four trailing X.

  • CLEANUP => 1 - remove the directory (and its contents) at exit.

Παραδείγματα#

use File::Temp qw/ tempdir /;
my $dir = tempdir(CLEANUP => 1);
open my $fh, '>', "$dir/notes.txt";

## $dir and its contents are removed at process exit
my $dir = tempdir('buildXXXXXX', DIR => '/var/tmp');

## directory remains after the process exits (no CLEANUP)

Οριακές περιπτώσεις#

  • Called as File::Temp->tempdir (method form): croaks.

  • Parent directory missing or not a directory: croaks.

  • Without CLEANUP, the directory persists - the caller owns it.

Διαφορές από το upstream#

Fully compatible with upstream File::Temp 0.2312.

Δείτε επίσης#

  • File::Temp->newdir - OO form whose object removes the tree on destruction.

  • mkdtemp - template-only low-level variant.

  • tempfile - file counterpart with the same option vocabulary.

  • cleanup - trigger registered cleanups manually.