tempnam#

Return a candidate filename under $dir starting with $prefix — does not create the file.

Synopsis#

my $name = tempnam('/var/tmp', 'cache_');

What you get back#

A full path string "$dir/${prefix}XXXXXXXX" with the Xs replaced by random characters. The caller is responsible for opening the file, and there is a race between name selection and open.

Examples#

use File::Temp qw/ tempnam /;
my $name = tempnam('/tmp', 'sess-');
open my $fh, '>', $name or die;

Edge cases#

  • Wrong arg count: croaks with a usage message.

  • Like mktemp, unsafe against attackers — prefer tempfile.

Differences from upstream#

Fully compatible with upstream File::Temp 0.2312.

See also#

  • tempfile — race-safe replacement returning both filehandle and name.

  • mktemp — similar idea with a caller-supplied template.