Re: perlfaq5: How do I make a temporary file name?

[email protected] (Robert Spier) Sun, 19 Dec 2004 22:25:35 -0800
Newsgroups perl.perlfaq.workers,perl.documentation
Message-ID <[email protected]>
+1.

Nifty.

This snuck in with PerlIO.  (See perlio.c and PerlIO_tmpfile and
PerlIO_open).

It uses mkstemp if available (with the downside of being hardcoded to
use /tmp) or uses tmpfile otherwise.  (Which also uses /tmp on Linux,
but is system dependent.)

-R

>  
>  =head2 How do I make a temporary file name?
>  
> -Use the File::Temp module, see L<File::Temp> for more information.
> +If you don't need to know the name of the file, you can use C<open()>
> +with C<undef> in place of the file name.  The C<open()> function
> +creates an anonymous temporary file.
> +
> +       open my $tmp, '+>', undef or die $!;
> +
> +Otherwise, you can use the File::Temp module.
>  
>    use File::Temp qw/ tempfile tempdir /;
> 
> -- 
> brian d foy, [email protected]