```{index} single: tmpfile; File::Temp function ``` ```{index} single: File::Temp::tmpfile; Perl function ``` # tmpfile POSIX-style `tmpfile` — open an anonymous temporary file and return the filehandle. The file is unlinked immediately. ## Synopsis ```perl my $fh = tmpfile(); print $fh "scratch\n"; seek $fh, 0, 0; ``` ## What you get back An open read/write filehandle reference. There is no filename to hand out: the file is removed from the directory immediately after opening and exists only as long as `$fh` is open. ## Examples ```perl my $fh = tmpfile(); print $fh "line 1\n"; seek $fh, 0, 0; my $line = <$fh>; # "line 1\n" ``` ## Edge cases - On filesystems that refuse to unlink open files the file stays on disk until `$fh` is closed. ## Differences from upstream Fully compatible with upstream `File::Temp` 0.2312. ## See also - `tempfile` — gives you both filehandle and filename. - `tmpnam` — returns only a name (or `($fh, $name)` in list context).