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.