```{index} single: mkstemp; File::Temp function ``` ```{index} single: File::Temp::mkstemp; Perl function ``` # mkstemp Create a file from a template and return a filehandle together with its pathname. ## Synopsis ```perl my ($fh, $path) = mkstemp('/tmp/dataXXXXXX'); my $fh = mkstemp('/tmp/dataXXXXXX'); # scalar context ``` ## What you get back 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. ## Examples ```perl use File::Temp qw/ mkstemp /; my ($fh, $path) = mkstemp('/var/tmp/workXXXXXX'); print $fh "payload\n"; ``` ## Edge cases - Template with fewer than four trailing `X`s: croaks. - Wrong arg count: croaks with a usage message. ## Differences from upstream Fully compatible with upstream `File::Temp` 0.2312. ## See also - `tempfile` — higher-level variant accepting `DIR`, `SUFFIX`, `UNLINK`. - `mkstemps` — like `mkstemp` but keeps a literal suffix on the name. - `mkdtemp` — directory counterpart.