1File::Temp(3pm)        Perl Programmers Reference Guide        File::Temp(3pm)
2
3
4

NAME

6       File::Temp - return name and handle of a temporary file safely
7

SYNOPSIS

9         use File::Temp qw/ tempfile tempdir /;
10
11         $fh = tempfile();
12         ($fh, $filename) = tempfile();
13
14         ($fh, $filename) = tempfile( $template, DIR => $dir);
15         ($fh, $filename) = tempfile( $template, SUFFIX => '.dat');
16         ($fh, $filename) = tempfile( $template, TMPDIR => 1 );
17
18         binmode( $fh, ":utf8" );
19
20         $dir = tempdir( CLEANUP => 1 );
21         ($fh, $filename) = tempfile( DIR => $dir );
22
23       Object interface:
24
25         require File::Temp;
26         use File::Temp ();
27         use File::Temp qw/ :seekable /;
28
29         $fh = File::Temp->new();
30         $fname = $fh->filename;
31
32         $fh = File::Temp->new(TEMPLATE => $template);
33         $fname = $fh->filename;
34
35         $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );
36         print $tmp "Some data\n";
37         print "Filename is $tmp\n";
38         $tmp->seek( 0, SEEK_END );
39
40       The following interfaces are provided for compatibility with existing
41       APIs. They should not be used in new code.
42
43       MkTemp family:
44
45         use File::Temp qw/ :mktemp  /;
46
47         ($fh, $file) = mkstemp( "tmpfileXXXXX" );
48         ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix);
49
50         $tmpdir = mkdtemp( $template );
51
52         $unopened_file = mktemp( $template );
53
54       POSIX functions:
55
56         use File::Temp qw/ :POSIX /;
57
58         $file = tmpnam();
59         $fh = tmpfile();
60
61         ($fh, $file) = tmpnam();
62
63       Compatibility functions:
64
65         $unopened_file = File::Temp::tempnam( $dir, $pfx );
66

DESCRIPTION

68       "File::Temp" can be used to create and open temporary files in a safe
69       way.  There is both a function interface and an object-oriented
70       interface.  The File::Temp constructor or the tempfile() function can
71       be used to return the name and the open filehandle of a temporary file.
72       The tempdir() function can be used to create a temporary directory.
73
74       The security aspect of temporary file creation is emphasized such that
75       a filehandle and filename are returned together.  This helps guarantee
76       that a race condition can not occur where the temporary file is created
77       by another process between checking for the existence of the file and
78       its opening.  Additional security levels are provided to check, for
79       example, that the sticky bit is set on world writable directories.  See
80       "safe_level" for more information.
81
82       For compatibility with popular C library functions, Perl
83       implementations of the mkstemp() family of functions are provided.
84       These are, mkstemp(), mkstemps(), mkdtemp() and mktemp().
85
86       Additionally, implementations of the standard POSIX tmpnam() and
87       tmpfile() functions are provided if required.
88
89       Implementations of mktemp(), tmpnam(), and tempnam() are provided, but
90       should be used with caution since they return only a filename that was
91       valid when function was called, so cannot guarantee that the file will
92       not exist by the time the caller opens the filename.
93
94       Filehandles returned by these functions support the seekable methods.
95

OBJECT-ORIENTED INTERFACE

97       This is the primary interface for interacting with "File::Temp". Using
98       the OO interface a temporary file can be created when the object is
99       constructed and the file can be removed when the object is no longer
100       required.
101
102       Note that there is no method to obtain the filehandle from the
103       "File::Temp" object. The object itself acts as a filehandle. Also, the
104       object is configured such that it stringifies to the name of the
105       temporary file, and can be compared to a filename directly. The object
106       isa "IO::Handle" and isa "IO::Seekable" so all those methods are
107       available.
108
109       new Create a temporary file object.
110
111             my $tmp = File::Temp->new();
112
113           by default the object is constructed as if "tempfile" was called
114           without options, but with the additional behaviour that the
115           temporary file is removed by the object destructor if UNLINK is set
116           to true (the default).
117
118           Supported arguments are the same as for "tempfile": UNLINK
119           (defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the
120           filename template is specified using the TEMPLATE option. The OPEN
121           option is not supported (the file is always opened).
122
123            $tmp = File::Temp->new( TEMPLATE => 'tempXXXXX',
124                                   DIR => 'mydir',
125                                   SUFFIX => '.dat');
126
127           Arguments are case insensitive.
128
129           Can call croak() if an error occurs.
130
131       newdir
132           Create a temporary directory using an object oriented interface.
133
134             $dir = File::Temp->newdir();
135
136           By default the directory is deleted when the object goes out of
137           scope.
138
139           Supports the same options as the "tempdir" function. Note that
140           directories created with this method default to CLEANUP => 1.
141
142             $dir = File::Temp->newdir( $template, %options );
143
144       filename
145           Return the name of the temporary file associated with this object
146           (if the object was created using the "new" constructor).
147
148             $filename = $tmp->filename;
149
150           This method is called automatically when the object is used as a
151           string.
152
153       dirname
154           Return the name of the temporary directory associated with this
155           object (if the object was created using the "newdir" constructor).
156
157             $dirname = $tmpdir->dirname;
158
159           This method is called automatically when the object is used in
160           string context.
161
162       unlink_on_destroy
163           Control whether the file is unlinked when the object goes out of
164           scope.  The file is removed if this value is true and $KEEP_ALL is
165           not.
166
167            $fh->unlink_on_destroy( 1 );
168
169           Default is for the file to be removed.
170
171       DESTROY
172           When the object goes out of scope, the destructor is called. This
173           destructor will attempt to unlink the file (using "unlink1") if the
174           constructor was called with UNLINK set to 1 (the default state if
175           UNLINK is not specified).
176
177           No error is given if the unlink fails.
178
179           If the object has been passed to a child process during a fork, the
180           file will be deleted when the object goes out of scope in the
181           parent.
182
183           For a temporary directory object the directory will be removed
184           unless the CLEANUP argument was used in the constructor (and set to
185           false) or "unlink_on_destroy" was modified after creation.
186
187           If the global variable $KEEP_ALL is true, the file or directory
188           will not be removed.
189

FUNCTIONS

191       This section describes the recommended interface for generating
192       temporary files and directories.
193
194       tempfile
195           This is the basic function to generate temporary files.  The
196           behaviour of the file can be changed using various options:
197
198             $fh = tempfile();
199             ($fh, $filename) = tempfile();
200
201           Create a temporary file in  the directory specified for temporary
202           files, as specified by the tmpdir() function in File::Spec.
203
204             ($fh, $filename) = tempfile($template);
205
206           Create a temporary file in the current directory using the supplied
207           template.  Trailing `X' characters are replaced with random letters
208           to generate the filename.  At least four `X' characters must be
209           present at the end of the template.
210
211             ($fh, $filename) = tempfile($template, SUFFIX => $suffix)
212
213           Same as previously, except that a suffix is added to the template
214           after the `X' translation.  Useful for ensuring that a temporary
215           filename has a particular extension when needed by other
216           applications.  But see the WARNING at the end.
217
218             ($fh, $filename) = tempfile($template, DIR => $dir);
219
220           Translates the template as before except that a directory name is
221           specified.
222
223             ($fh, $filename) = tempfile($template, TMPDIR => 1);
224
225           Equivalent to specifying a DIR of "File::Spec->tmpdir", writing the
226           file into the same temporary directory as would be used if no
227           template was specified at all.
228
229             ($fh, $filename) = tempfile($template, UNLINK => 1);
230
231           Return the filename and filehandle as before except that the file
232           is automatically removed when the program exits (dependent on
233           $KEEP_ALL). Default is for the file to be removed if a file handle
234           is requested and to be kept if the filename is requested. In a
235           scalar context (where no filename is returned) the file is always
236           deleted either (depending on the operating system) on exit or when
237           it is closed (unless $KEEP_ALL is true when the temp file is
238           created).
239
240           Use the object-oriented interface if fine-grained control of when a
241           file is removed is required.
242
243           If the template is not specified, a template is always
244           automatically generated. This temporary file is placed in tmpdir()
245           (File::Spec) unless a directory is specified explicitly with the
246           DIR option.
247
248             $fh = tempfile( DIR => $dir );
249
250           If called in scalar context, only the filehandle is returned and
251           the file will automatically be deleted when closed on operating
252           systems that support this (see the description of tmpfile()
253           elsewhere in this document).  This is the preferred mode of
254           operation, as if you only have a filehandle, you can never create a
255           race condition by fumbling with the filename. On systems that can
256           not unlink an open file or can not mark a file as temporary when it
257           is opened (for example, Windows NT uses the "O_TEMPORARY" flag) the
258           file is marked for deletion when the program ends (equivalent to
259           setting UNLINK to 1). The "UNLINK" flag is ignored if present.
260
261             (undef, $filename) = tempfile($template, OPEN => 0);
262
263           This will return the filename based on the template but will not
264           open this file.  Cannot be used in conjunction with UNLINK set to
265           true. Default is to always open the file to protect from possible
266           race conditions. A warning is issued if warnings are turned on.
267           Consider using the tmpnam() and mktemp() functions described
268           elsewhere in this document if opening the file is not required.
269
270           If the operating system supports it (for example BSD derived
271           systems), the filehandle will be opened with O_EXLOCK (open with
272           exclusive file lock).  This can sometimes cause problems if the
273           intention is to pass the filename to another system that expects to
274           take an exclusive lock itself (such as DBD::SQLite) whilst ensuring
275           that the tempfile is not reused. In this situation the "EXLOCK"
276           option can be passed to tempfile. By default EXLOCK will be true
277           (this retains compatibility with earlier releases).
278
279             ($fh, $filename) = tempfile($template, EXLOCK => 0);
280
281           Options can be combined as required.
282
283           Will croak() if there is an error.
284
285       tempdir
286           This is the recommended interface for creation of temporary
287           directories.  By default the directory will not be removed on exit
288           (that is, it won't be temporary; this behaviour can not be changed
289           because of issues with backwards compatibility). To enable removal
290           either use the CLEANUP option which will trigger removal on program
291           exit, or consider using the "newdir" method in the object interface
292           which will allow the directory to be cleaned up when the object
293           goes out of scope.
294
295           The behaviour of the function depends on the arguments:
296
297             $tempdir = tempdir();
298
299           Create a directory in tmpdir() (see File::Spec).
300
301             $tempdir = tempdir( $template );
302
303           Create a directory from the supplied template. This template is
304           similar to that described for tempfile(). `X' characters at the end
305           of the template are replaced with random letters to construct the
306           directory name. At least four `X' characters must be in the
307           template.
308
309             $tempdir = tempdir ( DIR => $dir );
310
311           Specifies the directory to use for the temporary directory.  The
312           temporary directory name is derived from an internal template.
313
314             $tempdir = tempdir ( $template, DIR => $dir );
315
316           Prepend the supplied directory name to the template. The template
317           should not include parent directory specifications itself. Any
318           parent directory specifications are removed from the template
319           before prepending the supplied directory.
320
321             $tempdir = tempdir ( $template, TMPDIR => 1 );
322
323           Using the supplied template, create the temporary directory in a
324           standard location for temporary files. Equivalent to doing
325
326             $tempdir = tempdir ( $template, DIR => File::Spec->tmpdir);
327
328           but shorter. Parent directory specifications are stripped from the
329           template itself. The "TMPDIR" option is ignored if "DIR" is set
330           explicitly.  Additionally, "TMPDIR" is implied if neither a
331           template nor a directory are supplied.
332
333             $tempdir = tempdir( $template, CLEANUP => 1);
334
335           Create a temporary directory using the supplied template, but
336           attempt to remove it (and all files inside it) when the program
337           exits. Note that an attempt will be made to remove all files from
338           the directory even if they were not created by this module
339           (otherwise why ask to clean it up?). The directory removal is made
340           with the rmtree() function from the File::Path module.  Of course,
341           if the template is not specified, the temporary directory will be
342           created in tmpdir() and will also be removed at program exit.
343
344           Will croak() if there is an error.
345

MKTEMP FUNCTIONS

347       The following functions are Perl implementations of the mktemp() family
348       of temp file generation system calls.
349
350       mkstemp
351           Given a template, returns a filehandle to the temporary file and
352           the name of the file.
353
354             ($fh, $name) = mkstemp( $template );
355
356           In scalar context, just the filehandle is returned.
357
358           The template may be any filename with some number of X's appended
359           to it, for example /tmp/temp.XXXX. The trailing X's are replaced
360           with unique alphanumeric combinations.
361
362           Will croak() if there is an error.
363
364       mkstemps
365           Similar to mkstemp(), except that an extra argument can be supplied
366           with a suffix to be appended to the template.
367
368             ($fh, $name) = mkstemps( $template, $suffix );
369
370           For example a template of "testXXXXXX" and suffix of ".dat" would
371           generate a file similar to testhGji_w.dat.
372
373           Returns just the filehandle alone when called in scalar context.
374
375           Will croak() if there is an error.
376
377       mkdtemp
378           Create a directory from a template. The template must end in X's
379           that are replaced by the routine.
380
381             $tmpdir_name = mkdtemp($template);
382
383           Returns the name of the temporary directory created.
384
385           Directory must be removed by the caller.
386
387           Will croak() if there is an error.
388
389       mktemp
390           Returns a valid temporary filename but does not guarantee that the
391           file will not be opened by someone else.
392
393             $unopened_file = mktemp($template);
394
395           Template is the same as that required by mkstemp().
396
397           Will croak() if there is an error.
398

POSIX FUNCTIONS

400       This section describes the re-implementation of the tmpnam() and
401       tmpfile() functions described in POSIX using the mkstemp() from this
402       module.
403
404       Unlike the POSIX implementations, the directory used for the temporary
405       file is not specified in a system include file ("P_tmpdir") but simply
406       depends on the choice of tmpdir() returned by File::Spec. On some
407       implementations this location can be set using the "TMPDIR" environment
408       variable, which may not be secure.  If this is a problem, simply use
409       mkstemp() and specify a template.
410
411       tmpnam
412           When called in scalar context, returns the full name (including
413           path) of a temporary file (uses mktemp()). The only check is that
414           the file does not already exist, but there is no guarantee that
415           that condition will continue to apply.
416
417             $file = tmpnam();
418
419           When called in list context, a filehandle to the open file and a
420           filename are returned. This is achieved by calling mkstemp() after
421           constructing a suitable template.
422
423             ($fh, $file) = tmpnam();
424
425           If possible, this form should be used to prevent possible race
426           conditions.
427
428           See "tmpdir" in File::Spec for information on the choice of
429           temporary directory for a particular operating system.
430
431           Will croak() if there is an error.
432
433       tmpfile
434           Returns the filehandle of a temporary file.
435
436             $fh = tmpfile();
437
438           The file is removed when the filehandle is closed or when the
439           program exits. No access to the filename is provided.
440
441           If the temporary file can not be created undef is returned.
442           Currently this command will probably not work when the temporary
443           directory is on an NFS file system.
444
445           Will croak() if there is an error.
446

ADDITIONAL FUNCTIONS

448       These functions are provided for backwards compatibility with common
449       tempfile generation C library functions.
450
451       They are not exported and must be addressed using the full package
452       name.
453
454       tempnam
455           Return the name of a temporary file in the specified directory
456           using a prefix. The file is guaranteed not to exist at the time the
457           function was called, but such guarantees are good for one clock
458           tick only.  Always use the proper form of "sysopen" with "O_CREAT |
459           O_EXCL" if you must open such a filename.
460
461             $filename = File::Temp::tempnam( $dir, $prefix );
462
463           Equivalent to running mktemp() with $dir/$prefixXXXXXXXX (using
464           unix file convention as an example)
465
466           Because this function uses mktemp(), it can suffer from race
467           conditions.
468
469           Will croak() if there is an error.
470

UTILITY FUNCTIONS

472       Useful functions for dealing with the filehandle and filename.
473
474       unlink0
475           Given an open filehandle and the associated filename, make a safe
476           unlink. This is achieved by first checking that the filename and
477           filehandle initially point to the same file and that the number of
478           links to the file is 1 (all fields returned by stat() are
479           compared).  Then the filename is unlinked and the filehandle
480           checked once again to verify that the number of links on that file
481           is now 0.  This is the closest you can come to making sure that the
482           filename unlinked was the same as the file whose descriptor you
483           hold.
484
485             unlink0($fh, $path)
486                or die "Error unlinking file $path safely";
487
488           Returns false on error but croaks() if there is a security anomaly.
489           The filehandle is not closed since on some occasions this is not
490           required.
491
492           On some platforms, for example Windows NT, it is not possible to
493           unlink an open file (the file must be closed first). On those
494           platforms, the actual unlinking is deferred until the program ends
495           and good status is returned. A check is still performed to make
496           sure that the filehandle and filename are pointing to the same
497           thing (but not at the time the end block is executed since the
498           deferred removal may not have access to the filehandle).
499
500           Additionally, on Windows NT not all the fields returned by stat()
501           can be compared. For example, the "dev" and "rdev" fields seem to
502           be different.  Also, it seems that the size of the file returned by
503           stat() does not always agree, with "stat(FH)" being more accurate
504           than "stat(filename)", presumably because of caching issues even
505           when using autoflush (this is usually overcome by waiting a while
506           after writing to the tempfile before attempting to "unlink0" it).
507
508           Finally, on NFS file systems the link count of the file handle does
509           not always go to zero immediately after unlinking. Currently, this
510           command is expected to fail on NFS disks.
511
512           This function is disabled if the global variable $KEEP_ALL is true
513           and an unlink on open file is supported. If the unlink is to be
514           deferred to the END block, the file is still registered for
515           removal.
516
517           This function should not be called if you are using the object
518           oriented interface since the it will interfere with the object
519           destructor deleting the file.
520
521       cmpstat
522           Compare "stat" of filehandle with "stat" of provided filename.
523           This can be used to check that the filename and filehandle
524           initially point to the same file and that the number of links to
525           the file is 1 (all fields returned by stat() are compared).
526
527             cmpstat($fh, $path)
528                or die "Error comparing handle with file";
529
530           Returns false if the stat information differs or if the link count
531           is greater than 1. Calls croak if there is a security anomaly.
532
533           On certain platforms, for example Windows, not all the fields
534           returned by stat() can be compared. For example, the "dev" and
535           "rdev" fields seem to be different in Windows.  Also, it seems that
536           the size of the file returned by stat() does not always agree, with
537           "stat(FH)" being more accurate than "stat(filename)", presumably
538           because of caching issues even when using autoflush (this is
539           usually overcome by waiting a while after writing to the tempfile
540           before attempting to "unlink0" it).
541
542           Not exported by default.
543
544       unlink1
545           Similar to "unlink0" except after file comparison using cmpstat,
546           the filehandle is closed prior to attempting to unlink the file.
547           This allows the file to be removed without using an END block, but
548           does mean that the post-unlink comparison of the filehandle state
549           provided by "unlink0" is not available.
550
551             unlink1($fh, $path)
552                or die "Error closing and unlinking file";
553
554           Usually called from the object destructor when using the OO
555           interface.
556
557           Not exported by default.
558
559           This function is disabled if the global variable $KEEP_ALL is true.
560
561           Can call croak() if there is a security anomaly during the stat()
562           comparison.
563
564       cleanup
565           Calling this function will cause any temp files or temp directories
566           that are registered for removal to be removed. This happens
567           automatically when the process exits but can be triggered manually
568           if the caller is sure that none of the temp files are required.
569           This method can be registered as an Apache callback.
570
571           On OSes where temp files are automatically removed when the temp
572           file is closed, calling this function will have no effect other
573           than to remove temporary directories (which may include temporary
574           files).
575
576             File::Temp::cleanup();
577
578           Not exported by default.
579

PACKAGE VARIABLES

581       These functions control the global state of the package.
582
583       safe_level
584           Controls the lengths to which the module will go to check the
585           safety of the temporary file or directory before proceeding.
586           Options are:
587
588           STANDARD
589                   Do the basic security measures to ensure the directory
590                   exists and is writable, that temporary files are opened
591                   only if they do not already exist, and that possible race
592                   conditions are avoided.  Finally the unlink0 function is
593                   used to remove files safely.
594
595           MEDIUM  In addition to the STANDARD security, the output directory
596                   is checked to make sure that it is owned either by root or
597                   the user running the program. If the directory is writable
598                   by group or by other, it is then checked to make sure that
599                   the sticky bit is set.
600
601                   Will not work on platforms that do not support the "-k"
602                   test for sticky bit.
603
604           HIGH    In addition to the MEDIUM security checks, also check for
605                   the possibility of ``chown() giveaway'' using the POSIX
606                   sysconf() function. If this is a possibility, each
607                   directory in the path is checked in turn for safeness,
608                   recursively walking back to the root directory.
609
610                   For platforms that do not support the POSIX
611                   "_PC_CHOWN_RESTRICTED" symbol (for example, Windows NT) it
612                   is assumed that ``chown() giveaway'' is possible and the
613                   recursive test is performed.
614
615           The level can be changed as follows:
616
617             File::Temp->safe_level( File::Temp::HIGH );
618
619           The level constants are not exported by the module.
620
621           Currently, you must be running at least perl v5.6.0 in order to run
622           with MEDIUM or HIGH security. This is simply because the safety
623           tests use functions from Fcntl that are not available in older
624           versions of perl. The problem is that the version number for Fcntl
625           is the same in perl 5.6.0 and in 5.005_03 even though they are
626           different versions.
627
628           On systems that do not support the HIGH or MEDIUM safety levels
629           (for example Win NT or OS/2) any attempt to change the level will
630           be ignored. The decision to ignore rather than raise an exception
631           allows portable programs to be written with high security in mind
632           for the systems that can support this without those programs
633           failing on systems where the extra tests are irrelevant.
634
635           If you really need to see whether the change has been accepted
636           simply examine the return value of "safe_level".
637
638             $newlevel = File::Temp->safe_level( File::Temp::HIGH );
639             die "Could not change to high security"
640                 if $newlevel != File::Temp::HIGH;
641
642       TopSystemUID
643           This is the highest UID on the current system that refers to a root
644           UID. This is used to make sure that the temporary directory is
645           owned by a system UID ("root", "bin", "sys" etc) rather than simply
646           by root.
647
648           This is required since on many unix systems "/tmp" is not owned by
649           root.
650
651           Default is to assume that any UID less than or equal to 10 is a
652           root UID.
653
654             File::Temp->top_system_uid(10);
655             my $topid = File::Temp->top_system_uid;
656
657           This value can be adjusted to reduce security checking if required.
658           The value is only relevant when "safe_level" is set to MEDIUM or
659           higher.
660
661       $KEEP_ALL
662           Controls whether temporary files and directories should be retained
663           regardless of any instructions in the program to remove them
664           automatically.  This is useful for debugging but should not be used
665           in production code.
666
667             $File::Temp::KEEP_ALL = 1;
668
669           Default is for files to be removed as requested by the caller.
670
671           In some cases, files will only be retained if this variable is true
672           when the file is created. This means that you can not create a
673           temporary file, set this variable and expect the temp file to still
674           be around when the program exits.
675
676       $DEBUG
677           Controls whether debugging messages should be enabled.
678
679             $File::Temp::DEBUG = 1;
680
681           Default is for debugging mode to be disabled.
682

WARNING

684       For maximum security, endeavour always to avoid ever looking at,
685       touching, or even imputing the existence of the filename.  You do not
686       know that that filename is connected to the same file as the handle you
687       have, and attempts to check this can only trigger more race conditions.
688       It's far more secure to use the filehandle alone and dispense with the
689       filename altogether.
690
691       If you need to pass the handle to something that expects a filename
692       then, on a unix system, use ""/dev/fd/" . fileno($fh)" for arbitrary
693       programs, or more generally ""+<=&" . fileno($fh)" for Perl programs.
694       You will have to clear the close-on-exec bit on that file descriptor
695       before passing it to another process.
696
697           use Fcntl qw/F_SETFD F_GETFD/;
698           fcntl($tmpfh, F_SETFD, 0)
699               or die "Can't clear close-on-exec flag on temp fh: $!\n";
700
701   Temporary files and NFS
702       Some problems are associated with using temporary files that reside on
703       NFS file systems and it is recommended that a local filesystem is used
704       whenever possible. Some of the security tests will most probably fail
705       when the temp file is not local. Additionally, be aware that the
706       performance of I/O operations over NFS will not be as good as for a
707       local disk.
708
709   Forking
710       In some cases files created by File::Temp are removed from within an
711       END block. Since END blocks are triggered when a child process exits
712       (unless "POSIX::_exit()" is used by the child) File::Temp takes care to
713       only remove those temp files created by a particular process ID. This
714       means that a child will not attempt to remove temp files created by the
715       parent process.
716
717       If you are forking many processes in parallel that are all creating
718       temporary files, you may need to reset the random number seed using
719       srand(EXPR) in each child else all the children will attempt to walk
720       through the same set of random file names and may well cause themselves
721       to give up if they exceed the number of retry attempts.
722
723   Directory removal
724       Note that if you have chdir'ed into the temporary directory and it is
725       subsequently cleaned up (either in the END block or as part of object
726       destruction), then you will get a warning from File::Path::rmtree().
727
728   BINMODE
729       The file returned by File::Temp will have been opened in binary mode if
730       such a mode is available. If that is not correct, use the "binmode()"
731       function to change the mode of the filehandle.
732
733       Note that you can modify the encoding of a file opened by File::Temp
734       also by using "binmode()".
735

HISTORY

737       Originally began life in May 1999 as an XS interface to the system
738       mkstemp() function. In March 2000, the OpenBSD mkstemp() code was
739       translated to Perl for total control of the code's security checking,
740       to ensure the presence of the function regardless of operating system
741       and to help with portability. The module was shipped as a standard part
742       of perl from v5.6.1.
743

SEE ALSO

745       "tmpnam" in POSIX, "tmpfile" in POSIX, File::Spec, File::Path
746
747       See IO::File and File::MkTemp, Apache::TempFile for different
748       implementations of temporary file handling.
749
750       See File::Tempdir for an alternative object-oriented wrapper for the
751       "tempdir" function.
752

AUTHOR

754       Tim Jenness <tjenness@cpan.org>
755
756       Copyright (C) 2007-2009 Tim Jenness.  Copyright (C) 1999-2007 Tim
757       Jenness and the UK Particle Physics and Astronomy Research Council. All
758       Rights Reserved.  This program is free software; you can redistribute
759       it and/or modify it under the same terms as Perl itself.
760
761       Original Perl implementation loosely based on the OpenBSD C code for
762       mkstemp(). Thanks to Tom Christiansen for suggesting that this module
763       should be written and providing ideas for code improvements and
764       security enhancements.
765
766
767
768perl v5.12.4                      2011-06-01                   File::Temp(3pm)
Impressum