📄 file::temp.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Temp 3".TH Temp 3 "2007-12-21" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"File::Temp \- return name and handle of a temporary file safely.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 1\& use File::Temp qw/ tempfile tempdir /;\&\& $fh = tempfile();\& ($fh, $filename) = tempfile();\&\& ($fh, $filename) = tempfile( $template, DIR => $dir);\& ($fh, $filename) = tempfile( $template, SUFFIX => \*(Aq.dat\*(Aq);\& ($fh, $filename) = tempfile( $template, TMPDIR => 1 );\&\& binmode( $fh, ":utf8" );\&\& $dir = tempdir( CLEANUP => 1 );\& ($fh, $filename) = tempfile( DIR => $dir );.Ve.PPObject interface:.PP.Vb 3\& require File::Temp;\& use File::Temp ();\& use File::Temp qw/ :seekable /;\&\& $fh = File::Temp\->new();\& $fname = $fh\->filename;\&\& $fh = File::Temp\->new(TEMPLATE => $template);\& $fname = $fh\->filename;\&\& $tmp = File::Temp\->new( UNLINK => 0, SUFFIX => \*(Aq.dat\*(Aq );\& print $tmp "Some data\en";\& print "Filename is $tmp\en";\& $tmp\->seek( 0, SEEK_END );.Ve.PPThe following interfaces are provided for compatibility withexisting APIs. They should not be used in new code..PPMkTemp family:.PP.Vb 1\& use File::Temp qw/ :mktemp /;\&\& ($fh, $file) = mkstemp( "tmpfileXXXXX" );\& ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix);\&\& $tmpdir = mkdtemp( $template );\&\& $unopened_file = mktemp( $template );.Ve.PP\&\s-1POSIX\s0 functions:.PP.Vb 1\& use File::Temp qw/ :POSIX /;\&\& $file = tmpnam();\& $fh = tmpfile();\&\& ($fh, $file) = tmpnam();.Ve.PPCompatibility functions:.PP.Vb 1\& $unopened_file = File::Temp::tempnam( $dir, $pfx );.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"\&\f(CW\*(C`File::Temp\*(C'\fR can be used to create and open temporary files in a safeway. There is both a function interface and an object-orientedinterface. The File::Temp constructor or the \fItempfile()\fR function canbe used to return the name and the open filehandle of a temporaryfile. The \fItempdir()\fR function can be used to create a temporarydirectory..PPThe security aspect of temporary file creation is emphasized such thata filehandle and filename are returned together. This helps guaranteethat a race condition can not occur where the temporary file iscreated by another process between checking for the existence of thefile and its opening. Additional security levels are provided tocheck, for example, that the sticky bit is set on world writabledirectories. See \*(L"safe_level\*(R" for more information..PPFor compatibility with popular C library functions, Perl implementations ofthe \fImkstemp()\fR family of functions are provided. These are, \fImkstemp()\fR,\&\fImkstemps()\fR, \fImkdtemp()\fR and \fImktemp()\fR..PPAdditionally, implementations of the standard \s-1POSIX\s0\&\fItmpnam()\fR and \fItmpfile()\fR functions are provided if required..PPImplementations of \fImktemp()\fR, \fItmpnam()\fR, and \fItempnam()\fR are provided,but should be used with caution since they return only a filenamethat was valid when function was called, so cannot guaranteethat the file will not exist by the time the caller opens the filename..PPFilehandles returned by these functions support the seekable methods..SH "OBJECT-ORIENTED INTERFACE".IX Header "OBJECT-ORIENTED INTERFACE"This is the primary interface for interacting with\&\f(CW\*(C`File::Temp\*(C'\fR. Using the \s-1OO\s0 interface a temporary file can be createdwhen the object is constructed and the file can be removed when theobject is no longer required..PPNote that there is no method to obtain the filehandle from the\&\f(CW\*(C`File::Temp\*(C'\fR object. The object itself acts as a filehandle. Also,the object is configured such that it stringifies to the name of thetemporary file, and can be compared to a filename directly. The objectisa \f(CW\*(C`IO::Handle\*(C'\fR and isa \f(CW\*(C`IO::Seekable\*(C'\fR so all those methods areavailable..IP "\fBnew\fR" 4.IX Item "new"Create a temporary file object..Sp.Vb 1\& my $tmp = File::Temp\->new();.Ve.Spby default the object is constructed as if \f(CW\*(C`tempfile\*(C'\fRwas called without options, but with the additional behaviourthat the temporary file is removed by the object destructorif \s-1UNLINK\s0 is set to true (the default)..SpSupported arguments are the same as for \f(CW\*(C`tempfile\*(C'\fR: \s-1UNLINK\s0(defaulting to true), \s-1DIR\s0, \s-1EXLOCK\s0 and \s-1SUFFIX\s0. Additionally, the filenametemplate is specified using the \s-1TEMPLATE\s0 option. The \s-1OPEN\s0 optionis not supported (the file is always opened)..Sp.Vb 3\& $tmp = File::Temp\->new( TEMPLATE => \*(AqtempXXXXX\*(Aq,\& DIR => \*(Aqmydir\*(Aq,\& SUFFIX => \*(Aq.dat\*(Aq);.Ve.SpArguments are case insensitive..SpCan call \fIcroak()\fR if an error occurs..IP "\fBnewdir\fR" 4.IX Item "newdir"Create a temporary directory using an object oriented interface..Sp.Vb 1\& $dir = File::Temp\->newdir();.Ve.SpBy default the directory is deleted when the object goes out of scope..SpSupports the same options as the \f(CW\*(C`tempdir\*(C'\fR function. Note that directoriescreated with this method default to \s-1CLEANUP\s0 => 1..Sp.Vb 1\& $dir = File::Temp\->newdir( $template, %options );.Ve.IP "\fBfilename\fR" 4.IX Item "filename"Return the name of the temporary file associated with this object(if the object was created using the \*(L"new\*(R" constructor)..Sp.Vb 1\& $filename = $tmp\->filename;.Ve.SpThis method is called automatically when the object is used asa string..IP "\fBdirname\fR" 4.IX Item "dirname"Return the name of the temporary directory associated with thisobject (if the object was created using the \*(L"newdir\*(R" constructor)..Sp.Vb 1\& $dirname = $tmpdir\->dirname;.Ve.SpThis method is called automatically when the object is used in string context..IP "\fBunlink_on_destroy\fR" 4.IX Item "unlink_on_destroy"Control whether the file is unlinked when the object goes out of scope.The file is removed if this value is true and \f(CW$KEEP_ALL\fR is not..Sp.Vb 1\& $fh\->unlink_on_destroy( 1 );.Ve.SpDefault is for the file to be removed..IP "\fB\s-1DESTROY\s0\fR" 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -