1File::Temp(3)         User Contributed Perl Documentation        File::Temp(3)
2
3
4

NAME

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

VERSION

9       version 0.2301
10

SYNOPSIS

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

DESCRIPTION

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

OBJECT-ORIENTED INTERFACE

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

FUNCTIONS

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

MKTEMP FUNCTIONS

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

POSIX FUNCTIONS

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

ADDITIONAL FUNCTIONS

463       These functions are provided for backwards compatibility with common
464       tempfile generation C library functions.
465
466       They are not exported and must be addressed using the full package
467       name.
468
469       tempnam
470           Return the name of a temporary file in the specified directory
471           using a prefix. The file is guaranteed not to exist at the time the
472           function was called, but such guarantees are good for one clock
473           tick only.  Always use the proper form of "sysopen" with "O_CREAT |
474           O_EXCL" if you must open such a filename.
475
476             $filename = File::Temp::tempnam( $dir, $prefix );
477
478           Equivalent to running mktemp() with $dir/$prefixXXXXXXXX (using
479           unix file convention as an example)
480
481           Because this function uses mktemp(), it can suffer from race
482           conditions.
483
484           Will croak() if there is an error.
485

UTILITY FUNCTIONS

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

PACKAGE VARIABLES

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

WARNING

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

HISTORY

762       Originally began life in May 1999 as an XS interface to the system
763       mkstemp() function. In March 2000, the OpenBSD mkstemp() code was
764       translated to Perl for total control of the code's security checking,
765       to ensure the presence of the function regardless of operating system
766       and to help with portability. The module was shipped as a standard part
767       of perl from v5.6.1.
768
769       Thanks to Tom Christiansen for suggesting that this module should be
770       written and providing ideas for code improvements and security
771       enhancements.
772

SEE ALSO

774       "tmpnam" in POSIX, "tmpfile" in POSIX, File::Spec, File::Path
775
776       See IO::File and File::MkTemp, Apache::TempFile for different
777       implementations of temporary file handling.
778
779       See File::Tempdir for an alternative object-oriented wrapper for the
780       "tempdir" function.
781
782       # vim: ts=2 sts=2 sw=2 et:
783

SUPPORT

785   Bugs / Feature Requests
786       Please report any bugs or feature requests through the issue tracker at
787       <https://rt.cpan.org/Public/Dist/Display.html?Name=File-Temp>.  You
788       will be notified automatically of any progress on your issue.
789
790   Source Code
791       This is open source software.  The code repository is available for
792       public review and contribution under the terms of the license.
793
794       <http://github.com/Perl-Toolchain-Gang/File-Temp>
795
796         git clone git://github.com/Perl-Toolchain-Gang/File-Temp.git
797

AUTHOR

799       Tim Jenness <tjenness@cpan.org>
800

CONTRIBUTORS

802       ·   Ben Tilly <btilly@gmail.com>
803
804       ·   David Golden <dagolden@cpan.org>
805
806       ·   Ed Avis <eda@linux01.wcl.local>
807
808       ·   James E. Keenan <jkeen@verizon.net>
809
810       ·   Kevin Ryde <user42@zip.com.au>
811
812       ·   Peter John Acklam <pjacklam@online.no>
813
815       This software is copyright (c) 2013 by Tim Jenness and the UK Particle
816       Physics and Astronomy Research Council.
817
818       This is free software; you can redistribute it and/or modify it under
819       the same terms as the Perl 5 programming language system itself.
820
821
822
823perl v5.16.3                      2013-04-11                     File::Temp(3)
Impressum