📄 ch25.htm
字号:
</BLOCKQUOTE></TD></TR></TABLE></CENTER><P><H3><A NAME="chownNUMERICALUIDNUMERICALGIDLIST">chown (NUMERICAL_UID, NUMERICAL_GID, LIST)</A></H3><P><B>Category:</B> File, UNIX<BR><B>Return Value:</B> SCALAR, the number of files successfullychanged.<BR><B>Definition:</B> Changes the ownership of the files in <TT>LIST</TT>to the user ID and the group ID specified as parameters.<BLOCKQUOTE><PRE>chown(1, 1, "test1.txt");</PRE></BLOCKQUOTE><H3><A NAME="chrNUMBER">chr (NUMBER)</A></H3><P><B>Category:</B> String<BR><B>Return Value:</B> SCALAR, the character represented by <TT>NUMBER</TT>.<BR><B>Definition:</B> Returns the ASCII character represented by<TT>NUMBER</TT>. For example, <TT>chr(69)</TT>is the letter E. See Appendix E, "ASCII Table" for moreinformation.<H3><A NAME="chrootDIRNAME">chroot (DIR_NAME)</A></H3><P><B>Category:</B> File, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false otherwise.<BR><B>Definition:</B> Changes the root directory of the current processto <TT>DIR_NAME</TT>. Which meansthat a filename like <TT>/john.dat</TT>might really refer to <TT>/root/users/~jmiller/john.dat</TT>.<BLOCKQUOTE><PRE>chroot("/usr/~waters");<BR></PRE></BLOCKQUOTE><p><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR><TD><B>Tip</B></TD></TR><TR><TD><BLOCKQUOTE>Your process must have superuser rights in order to successfully use this fuNCtion. It is used to make processes safer by only allowing them access to the subdirectory tree relevant to their purpose.</BLOCKQUOTE></TD></TR></TABLE></CENTER><P><H3><A NAME="closeFILEHANDLE">close (FILEHANDLE)</A></H3><P><B>Category:</B> File<BR><B>Return Value:</B> SCALAR, true if the file was closed correctly,false if not.<BR><B>Definition:</B> Closes the file opened with <TT>FILEHANDLE</TT>.This operation flushes all buffered output. If the file handlerefers to a pipe the Perl program waits until the process beingpiped to has finished.<BLOCKQUOTE><PRE>open(FILE, "test1.txt");# some file activityclose(FILE);</PRE></BLOCKQUOTE><H3><A NAME="closedirDIRHANDLE">closedir (DIRHANDLE)</A></H3><P><B>Category:</B> Directory, Files<BR><B>Return Value:</B> SCALAR, true if the directory was closedcorrectly, false if not.<BR><B>Definition:</B> Closes the directory opened by <TT>opendir()</TT>.<BLOCKQUOTE><PRE>opendir(DIR, ".");# some directory activityclosedir(DIR);</PRE></BLOCKQUOTE><H3><A NAME="connectSOCKETNAME">connect (SOCKET, NAME)</A></H3><P><B>Category:</B> Socket<BR><B>Return Value:</B> SCALAR, true if the connection was successful,otherwise false.<BR><B>Definition:</B> Attempts to connect to a remote socket. <TT>NAME</TT>must be a packed address of the correct type for the socket.<H3><A NAME="cosEXPR">cos ([EXPR])</A></H3><P><B>Category:</B> Math<BR><B>Return Value:</B> SCALAR, the cosine of <TT>EXPR</TT>or else <TT>$_</TT> is used if noexpression is specified.<BR><B>Definition:</B> Calculates a cosine.<BLOCKQUOTE><PRE>$temp = cos(60);</PRE></BLOCKQUOTE><H3><A NAME="cryptTEXTSALT">crypt (TEXT, SALT)</A></H3><P><B>Category:</B> String<BR><B>Return Value:</B> SCALAR, an eNCrypted string.<BR><B>Definition:</B> ENCrypts <TT>TEXT</TT>using a key (either <TT>SALT</TT>or the first two letters of <TT>TEXT</TT>).<BLOCKQUOTE><PRE>$eNCyptedString = crypt("Password","TR");</PRE></BLOCKQUOTE><H3><A NAME="dbmcloseHASH">dbmclose (HASH)</A></H3><P><B>Category:</B> Database<BR><B>Return Value:</B> SCALAR, true if the close was successful,false otherwise.<BR><B>Definition:</B> Undoes the linking of <TT>HASH</TT>to a dbm file.<BR><p><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR><TD><B>Tip</B></TD></TR><TR><TD><BLOCKQUOTE>This fuNCtion has been superseded by the <TT>untie()</TT> fuNCtion.</BLOCKQUOTE></TD></TR></TABLE></CENTER><P><H3><A NAME="dbmopenHASHDATABASENAMEMODE">dbmopen (HASH, DATABASE_NAME, MODE)</A></H3><P><B>Category:</B> Database<BR><B>Return Value:</B> None<BR><B>Definition:</B> Links <TT>HASH</TT>to <TT>DATABASE_NAME</TT>. If thedatabase does not exist, a new one with the specified <TT>MODE</TT>will be created.<BR><p><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR><TD><B>Tip</B></TD></TR><TR><TD><BLOCKQUOTE>This fuNCtion has been superseded by the <TT>tie()</TT> fuNCtion.</BLOCKQUOTE></TD></TR></TABLE></CENTER><P><H3><A NAME="definedEXPR">defined (EXPR)</A></H3><P><B>Category:</B> Miscellaneous<BR><B>Return Value:</B> SCALAR, true if <TT>EXPR</TT>has a real value, false otherwise.<BR><B>Definition:</B> There is a subtle distiNCtion between an undefinednull value and a defined null value. Some fuNCtions return undefinednull to indicate errors, while others return a defined null toindicate a particular result (use a comparison with the null stringto test for this rather than using <TT>defined()</TT>).<BLOCKQUOTE><PRE>@iexist = (1,2,3);print("exists.\n") if defined(@iexist);print("does not exist.\n") unless defined(@iexist);</PRE></BLOCKQUOTE><H3><A NAME="deleteEXPR">delete (EXPR)</A></H3><P><B>Category:</B> Hash<BR><B>Return Value:</B> SCALAR, the deleted value or the undefinedvalue if nothing was deleted.<BR><B>Definition:</B> Deletes an entry from an associative array.<TT>EXPR</TT> is the key for the entryto delete.<BLOCKQUOTE><PRE>%Hash = ('Jan' => 'One', 'Feb' => 'Two', 'Mar' => 'Three');delete($Hash{'Jan'});</PRE></BLOCKQUOTE><H3><A NAME="dieLIST">die ([LIST])</A></H3><P><B>Category:</B> Process<BR><B>Return Value:</B> None.<BR><B>Definition:</B> Terminates execution of the Perl script, printing<TT>LIST</TT> to STDERR. The exitvalue is the current value of <TT>$!</TT>which may have been set by a previous fuNCtion. If <TT>$!</TT>has a value of zero, <TT>$?</TT> willbe returned instead. If <TT>$?</TT>is zero, it exits with an exit value of 255. If <TT>LIST</TT>does not end in a newline, the text similar to "at test.plat line 10" will be appended to the end.<BLOCKQUOTE><PRE>die("Something fatal has happened and the script must die!");</PRE></BLOCKQUOTE><H3><A NAME="doSCRIPTNAME">do (SCRIPTNAME)</A></H3><P><B>Category:</B> Miscellaneous<BR><B>Return Value:</B> None<BR><B>Definition:</B> Executes the contents of a file as a Perl script.It is usually used to iNClude subroutines however it has beenmostly superseded by <TT>use()</TT>and <TT>require()</TT>.<H3><A NAME="dumpLABEL">dump ([LABEL])</A></H3><P><B>Category:</B> Process, UNIX<BR><B>Return Value:</B> None.<BR><B>Definition:</B> Causes the program to create a binary imageor core dump. You can reload the image using undump program. Whenreloaded, the program begins execution from the optional labelspecified. So it is possible to set up a program which initializesdata structures to <TT>dump()</TT>after the initialization so that execution is faster when reloadingthe dumped image.<H3><A NAME="eachHASH">each (HASH)</A></H3><P><B>Category:</B> Hash<BR><B>Return Value:</B> ARRAY, an entry (the key-value pair) in <TT>HASH</TT>.<BR><B>Definition:</B> Allows iteration over the entries in an associativearray. Each time it is evaluated, another key-value pair is returned.When all the entries have been returned, it returns an empty array.<BLOCKQUOTE><PRE>%NumberWord = ('1' => 'One', '2' => 'Two', '3' => 'Three');while (($key, $value) = each(%NumberWord)) { print("$key: $value\n");}</PRE></BLOCKQUOTE><H3><A NAME="endgrent">endgrent ( )</A></H3><P><B>Category:</B> Group, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the <TT>/etc/group</TT>file used by <TT>getgrent()</TT> andother group related fuNCtions.<BLOCKQUOTE><PRE>($name, $pw, $gid, @members) = getgrent();endgrent();</PRE></BLOCKQUOTE><H3><A NAME="endhostent">endhostent ( )</A></H3><P><B>Category:</B> Host, Sockets, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the TCP socket used by <TT>gethostbyname()</TT>and host related fuNCtions.<BLOCKQUOTE><PRE>$host = gethostbyname("lyNCh");endhostent();</PRE></BLOCKQUOTE><H3><A NAME="endnetent">endnetent ( )</A></H3><P><B>Category:</B> Network, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the <TT>/etc/networks</TT>file used by <TT>getnetent()</TT>and network related fuNCtions.<BLOCKQUOTE><PRE>($name, $aliases, $addrtype, $net) = getnetent();endnetent();</PRE></BLOCKQUOTE><H3><A NAME="endprotoent">endprotoent ( )</A></H3><P><B>Category:</B> Protocol, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the <TT>/etc/protocols</TT>file used by <TT>getprotoent()</TT>and protocol related fuNCtions.<BLOCKQUOTE><PRE>($name, $alias, $protocol) = getprotoent();endprotoent();</PRE></BLOCKQUOTE><H3><A NAME="endpwent">endpwent ( )</A></H3><P><B>Category:</B> Password, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the <TT>/etc/passwdfile</TT> used by <TT>getpwent()</TT>and password related fuNCtions.<BLOCKQUOTE><PRE>($name, $pass, $uid, $gid, $quota, $name, $gcos, $logindir, $shell) = getpwent();endpwent();</PRE></BLOCKQUOTE><H3><A NAME="endservent">endservent ( )</A></H3><P><B>Category:</B> Server, UNIX<BR><B>Return Value:</B> SCALAR, true if successful, false if not.<BR><B>Definition:</B> Closes the <TT>/etc/servers</TT>file used by <TT>getservent()</TT>and related fuNCtions.<BLOCKQUOTE><PRE>($name, $aliases, $port, $protocol) = getservent();endservent();</PRE></BLOCKQUOTE><H3><A NAME="eofFILEHANDLE">eof ([FILEHANDLE])</A></H3><P><B>Category:</B> File<BR><B>Return Value:</B> SCALAR, true if the next read on <TT>FILEHANDLE</TT>will be at the end of file, false if not.<BR><B>Definition:</B> Tests for the end of a file. This is done byreading the next character and then undoing this operation (sois only suitable on files where this can be done safely). If noargument is supplied the file tested is the last file which wasread. If the empty list is supplied then a pseudo file is createdof the files listed on the command line. This lets you test forthe end of the last file on the command line.<BLOCKQUOTE><PRE>open(FILE, "test1.txt");# some file activityprint("eof() returned ", eof(FILE) ? "TRUE" : "FALSE", "\n");close(FILE);</PRE></BLOCKQUOTE><H3><A NAME="evalEXPRBLOCK">eval ([EXPR | BLOCK])</A></H3><P><B>Category:</B> Miscellaneous<BR><B>Return Value:</B> The undefined value if a syntax error, aruntime error, or a <TT>die()</TT>fuNCtion occurs. Otherwise, the return value is the value of <TT>EXPR</TT>or the last statement in <TT>BLOCK</TT>.The return value can be any type.<BR><B>Definition:</B> Treats the expression like a Perl program andexecutes it. As the context of this execution is the same as thatof the script itself, variable definitions and subroutine definitionspersist. Syntax errors, runtime errors, and execution of the <TT>die()</TT>fuNCtion are trapped and an undefined result is returned. If suchan error does occur <TT>$@</TT> isset. <TT>$@</TT> will be equal toa defined null string if no errors are found. If no expressionis supplied, <TT>$_</TT> is the defaultargument. If the block syntax is used then the expressions inthe block are evaluated only oNCe within the script (which maybe more efficient for certain situations).<BR><p><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR><TD><B>Tip</B></TD></TR><TR><TD><BLOCKQUOTE><TT>eval()</TT> traps possible error conditions which would otherwise crash a program and so can be used to test if certain features are available which would cause runtime errors if used when not available. See <A HREF="ch13.htm" >Chapter 13</A>, "Handling Errors and Signals," for more information.</BLOCKQUOTE></TD></TR></TABLE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -