mkstemp#

Create a file from a template and return a filehandle together with its pathname.

Σύνοψη#

my ($fh, $path) = mkstemp('/tmp/dataXXXXXX');
my  $fh         = mkstemp('/tmp/dataXXXXXX');   # scalar context

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

In list context ($fh, $path); in scalar context just the filehandle. The template must end in at least four X characters, which are replaced atomically with random bytes.

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

use File::Temp qw/ mkstemp /;
my ($fh, $path) = mkstemp('/var/tmp/workXXXXXX');
print $fh "payload\n";

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

  • Template with fewer than four trailing Xs: croaks.

  • Wrong arg count: croaks with a usage message.

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

Fully compatible with upstream File::Temp 0.2312.

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

  • tempfile - higher-level variant accepting DIR, SUFFIX, UNLINK.

  • mkstemps - like mkstemp but keeps a literal suffix on the name.

  • mkdtemp - directory counterpart.