tmpnam#

POSIX-style tmpnam — in scalar context a candidate filename in the system temp directory; in list context a created file with its filehandle.

Synopsis#

my $name         = tmpnam();                # scalar: just a name
my ($fh, $name)  = tmpnam();                # list: creates the file

What you get back#

In scalar context a filename string in the system temp directory that does not exist at the moment of the call — there is still a race between picking it and opening it, so prefer tempfile. In list context, a freshly created file is returned along with its filehandle.

Examples#

use File::Temp qw/ tmpnam /;
my ($fh, $name) = tmpnam();                 # race-free file creation

Edge cases#

  • Scalar context does not create a file — callers must open the name themselves and accept the race.

Differences from upstream#

Fully compatible with upstream File::Temp 0.2312.

See also#

  • tempfile — the recommended race-safe replacement.

  • tmpfile — file is opened and unlinked immediately.

  • mkstemp — template-based creation.