⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file::temp.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 3 页
字号:
.IX Item "DESTROY"When the object goes out of scope, the destructor is called. Thisdestructor will attempt to unlink the file (using \f(CW\*(C`unlink1\*(C'\fR)if the constructor was called with \s-1UNLINK\s0 set to 1 (the default stateif \s-1UNLINK\s0 is not specified)..SpNo error is given if the unlink fails..SpIf the object has been passed to a child process during a fork, thefile will be deleted when the object goes out of scope in the parent..SpFor a temporary directory object the directory will be removedunless the \s-1CLEANUP\s0 argument was used in the constructor (and set tofalse) or \f(CW\*(C`unlink_on_destroy\*(C'\fR was modified after creation..SpIf the global variable \f(CW$KEEP_ALL\fR is true, the file or directorywill not be removed..SH "FUNCTIONS".IX Header "FUNCTIONS"This section describes the recommended interface for generatingtemporary files and directories..IP "\fBtempfile\fR" 4.IX Item "tempfile"This is the basic function to generate temporary files.The behaviour of the file can be changed using various options:.Sp.Vb 2\&  $fh = tempfile();\&  ($fh, $filename) = tempfile();.Ve.SpCreate a temporary file in  the directory specified for temporaryfiles, as specified by the \fItmpdir()\fR function in File::Spec..Sp.Vb 1\&  ($fh, $filename) = tempfile($template);.Ve.SpCreate a temporary file in the current directory using the suppliedtemplate.  Trailing `X' characters are replaced with random letters togenerate the filename.  At least four `X' characters must be presentat the end of the template..Sp.Vb 1\&  ($fh, $filename) = tempfile($template, SUFFIX => $suffix).Ve.SpSame as previously, except that a suffix is added to the templateafter the `X' translation.  Useful for ensuring that a temporaryfilename has a particular extension when needed by other applications.But see the \s-1WARNING\s0 at the end..Sp.Vb 1\&  ($fh, $filename) = tempfile($template, DIR => $dir);.Ve.SpTranslates the template as before except that a directory nameis specified..Sp.Vb 1\&  ($fh, $filename) = tempfile($template, TMPDIR => 1);.Ve.SpEquivalent to specifying a \s-1DIR\s0 of \*(L"File::Spec\->tmpdir\*(R", writing the fileinto the same temporary directory as would be used if no template wasspecified at all..Sp.Vb 1\&  ($fh, $filename) = tempfile($template, UNLINK => 1);.Ve.SpReturn the filename and filehandle as before except that the file isautomatically removed when the program exits (dependent on\&\f(CW$KEEP_ALL\fR). Default is for the file to be removed if a file handle isrequested and to be kept if the filename is requested. In a scalarcontext (where no filename is returned) the file is always deletedeither (depending on the operating system) on exit or when it isclosed (unless \f(CW$KEEP_ALL\fR is true when the temp file is created)..SpUse the object-oriented interface if fine-grained control of whena file is removed is required..SpIf the template is not specified, a template is alwaysautomatically generated. This temporary file is placed in \fItmpdir()\fR(File::Spec) unless a directory is specified explicitly with the\&\s-1DIR\s0 option..Sp.Vb 1\&  $fh = tempfile( DIR => $dir );.Ve.SpIf called in scalar context, only the filehandle is returned and thefile will automatically be deleted when closed on operating systemsthat support this (see the description of \fItmpfile()\fR elsewhere in thisdocument).  This is the preferred mode of operation, as if you onlyhave a filehandle, you can never create a race condition by fumblingwith the filename. On systems that can not unlink an open file or cannot mark a file as temporary when it is opened (for example, Windows\&\s-1NT\s0 uses the \f(CW\*(C`O_TEMPORARY\*(C'\fR flag) the file is marked for deletion whenthe program ends (equivalent to setting \s-1UNLINK\s0 to 1). The \f(CW\*(C`UNLINK\*(C'\fRflag is ignored if present..Sp.Vb 1\&  (undef, $filename) = tempfile($template, OPEN => 0);.Ve.SpThis will return the filename based on the template butwill not open this file.  Cannot be used in conjunction with\&\s-1UNLINK\s0 set to true. Default is to always open the fileto protect from possible race conditions. A warning is issuedif warnings are turned on. Consider using the \fItmpnam()\fRand \fImktemp()\fR functions described elsewhere in this documentif opening the file is not required..SpIf the operating system supports it (for example \s-1BSD\s0 derived systems), the filehandle will be opened with O_EXLOCK (open with exclusive file lock). This can sometimes cause problems if the intention is to pass the filename to another system that expects to take an exclusive lock itself (such as DBD::SQLite) whilst ensuring that the tempfile is not reused. In this situation the \*(L"\s-1EXLOCK\s0\*(R" option can be passed to tempfile. By default \s-1EXLOCK\s0 will be true (this retains compatibility with earlier releases)..Sp.Vb 1\&  ($fh, $filename) = tempfile($template, EXLOCK => 0);.Ve.SpOptions can be combined as required..SpWill \fIcroak()\fR if there is an error..IP "\fBtempdir\fR" 4.IX Item "tempdir"This is the recommended interface for creation of temporarydirectories.  By default the directory will not be removed on exit(that is, it won't be temporary; this behaviour can not be changedbecause of issues with backwards compatibility). To enable removaleither use the \s-1CLEANUP\s0 option which will trigger removal on programexit, or consider using the \*(L"newdir\*(R" method in the object interface whichwill allow the directory to be cleaned up when the object goes out ofscope..SpThe behaviour of the function depends on the arguments:.Sp.Vb 1\&  $tempdir = tempdir();.Ve.SpCreate a directory in \fItmpdir()\fR (see File::Spec)..Sp.Vb 1\&  $tempdir = tempdir( $template );.Ve.SpCreate a directory from the supplied template. This template issimilar to that described for \fItempfile()\fR. `X' characters at the endof the template are replaced with random letters to construct thedirectory name. At least four `X' characters must be in the template..Sp.Vb 1\&  $tempdir = tempdir ( DIR => $dir );.Ve.SpSpecifies the directory to use for the temporary directory.The temporary directory name is derived from an internal template..Sp.Vb 1\&  $tempdir = tempdir ( $template, DIR => $dir );.Ve.SpPrepend the supplied directory name to the template. The templateshould not include parent directory specifications itself. Any parentdirectory specifications are removed from the template beforeprepending the supplied directory..Sp.Vb 1\&  $tempdir = tempdir ( $template, TMPDIR => 1 );.Ve.SpUsing the supplied template, create the temporary directory ina standard location for temporary files. Equivalent to doing.Sp.Vb 1\&  $tempdir = tempdir ( $template, DIR => File::Spec\->tmpdir);.Ve.Spbut shorter. Parent directory specifications are stripped from thetemplate itself. The \f(CW\*(C`TMPDIR\*(C'\fR option is ignored if \f(CW\*(C`DIR\*(C'\fR is setexplicitly.  Additionally, \f(CW\*(C`TMPDIR\*(C'\fR is implied if neither a templatenor a directory are supplied..Sp.Vb 1\&  $tempdir = tempdir( $template, CLEANUP => 1);.Ve.SpCreate a temporary directory using the supplied template, butattempt to remove it (and all files inside it) when the programexits. Note that an attempt will be made to remove all files fromthe directory even if they were not created by this module (otherwisewhy ask to clean it up?). The directory removal is made withthe \fIrmtree()\fR function from the File::Path module.Of course, if the template is not specified, the temporary directorywill be created in \fItmpdir()\fR and will also be removed at program exit..SpWill \fIcroak()\fR if there is an error..SH "MKTEMP FUNCTIONS".IX Header "MKTEMP FUNCTIONS"The following functions are Perl implementations of the\&\fImktemp()\fR family of temp file generation system calls..IP "\fBmkstemp\fR" 4.IX Item "mkstemp"Given a template, returns a filehandle to the temporary file and the nameof the file..Sp.Vb 1\&  ($fh, $name) = mkstemp( $template );.Ve.SpIn scalar context, just the filehandle is returned..SpThe template may be any filename with some number of X's appendedto it, for example \fI/tmp/temp.XXXX\fR. The trailing X's are replacedwith unique alphanumeric combinations..SpWill \fIcroak()\fR if there is an error..IP "\fBmkstemps\fR" 4.IX Item "mkstemps"Similar to \fImkstemp()\fR, except that an extra argument can be suppliedwith a suffix to be appended to the template..Sp.Vb 1\&  ($fh, $name) = mkstemps( $template, $suffix );.Ve.SpFor example a template of \f(CW\*(C`testXXXXXX\*(C'\fR and suffix of \f(CW\*(C`.dat\*(C'\fRwould generate a file similar to \fItesthGji_w.dat\fR..SpReturns just the filehandle alone when called in scalar context..SpWill \fIcroak()\fR if there is an error..IP "\fBmkdtemp\fR" 4.IX Item "mkdtemp"Create a directory from a template. The template must end inX's that are replaced by the routine..Sp.Vb 1\&  $tmpdir_name = mkdtemp($template);.Ve.SpReturns the name of the temporary directory created..SpDirectory must be removed by the caller..SpWill \fIcroak()\fR if there is an error..IP "\fBmktemp\fR" 4.IX Item "mktemp"Returns a valid temporary filename but does not guaranteethat the file will not be opened by someone else..Sp.Vb 1\&  $unopened_file = mktemp($template);.Ve.SpTemplate is the same as that required by \fImkstemp()\fR..SpWill \fIcroak()\fR if there is an error..SH "POSIX FUNCTIONS".IX Header "POSIX FUNCTIONS"This section describes the re-implementation of the \fItmpnam()\fRand \fItmpfile()\fR functions described in \s-1POSIX\s0using the \fImkstemp()\fR from this module..PPUnlike the \s-1POSIX\s0 implementations, the directory usedfor the temporary file is not specified in a system includefile (\f(CW\*(C`P_tmpdir\*(C'\fR) but simply depends on the choice of \fItmpdir()\fRreturned by File::Spec. On some implementations thislocation can be set using the \f(CW\*(C`TMPDIR\*(C'\fR environment variable, whichmay not be secure.If this is a problem, simply use \fImkstemp()\fR and specify a template..IP "\fBtmpnam\fR" 4.IX Item "tmpnam"When called in scalar context, returns the full name (including path)of a temporary file (uses \fImktemp()\fR). The only check is that the file doesnot already exist, but there is no guarantee that that condition willcontinue to apply..Sp.Vb 1\&  $file = tmpnam();.Ve.SpWhen called in list context, a filehandle to the open file anda filename are returned. This is achieved by calling \fImkstemp()\fRafter constructing a suitable template..Sp.Vb 1\&  ($fh, $file) = tmpnam();.Ve.SpIf possible, this form should be used to prevent possiblerace conditions..SpSee \*(L"tmpdir\*(R" in File::Spec for information on the choice of temporarydirectory for a particular operating system..SpWill \fIcroak()\fR if there is an error..IP "\fBtmpfile\fR" 4.IX Item "tmpfile"Returns the filehandle of a temporary file..Sp.Vb 1\&  $fh = tmpfile();.Ve.SpThe file is removed when the filehandle is closed or when the programexits. No access to the filename is provided..SpIf the temporary file can not be created undef is returned.Currently this command will probably not work when the temporarydirectory is on an \s-1NFS\s0 file system..SpWill \fIcroak()\fR if there is an error..SH "ADDITIONAL FUNCTIONS".IX Header "ADDITIONAL FUNCTIONS"These functions are provided for backwards compatibilitywith common tempfile generation C library functions..PPThey are not exported and must be addressed using the full packagename..IP "\fBtempnam\fR" 4.IX Item "tempnam"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -