mktemp#

Fill in the trailing Xs of a template and return the resulting filename — does not create the file.

Synopsis#

my $name = mktemp('/tmp/dataXXXXXX');

What you get back#

A candidate filename string with random characters substituted for the trailing Xs. No file is created; the caller must open it themselves and accept the race between naming and opening.

Examples#

use File::Temp qw/ mktemp /;
my $name = mktemp('/var/tmp/snapXXXXXXXX');

Edge cases#

  • Template with fewer than four trailing Xs: croaks.

  • Wrong arg count: croaks with a usage message.

  • Unsafe against racing attackers — prefer tempfile.

Differences from upstream#

Fully compatible with upstream File::Temp 0.2312.

See also#

  • tempfile — race-safe replacement.

  • mkstemp — same idea, but also creates and opens the file.

  • tempnamdir + prefix variant.