📄 ch25.htm
字号:
chmod(0744, "test1.txt", "test2.txt");
</PRE>
</BLOCKQUOTE>
<H3><A NAME="chompSTRINGLIST">
chomp ([STRING | LIST])</A></H3>
<P>
<B>Category:</B> Array, String<BR>
<B>Return Value:</B> SCALAR, the number of characters removed.
<BR>
<B>Definition:</B> This is a safer alternative than the <TT>chop()</TT>
fuNCtion for removing characters at the end of strings. <TT>Chomp()</TT>
only removes characters that correspond to the value of <TT>$/</TT>
(the input line separator). It can be given a list of strings
upon which to perform this operation. When given no arguments
the chomp operation is performed on <TT>$_</TT>.
<BLOCKQUOTE>
<PRE>
$temp = "AAAAA!\n";
print("chomp(\$temp) returned ", chomp($temp), ".\n");
</PRE>
</BLOCKQUOTE>
<H3><A NAME="chopSTRINGLIST">
chop ([STRING | LIST])</A></H3>
<P>
<B>Category:</B> Array, String<BR>
<B>Return Value:</B> SCALAR, the last character that was removed.
<BR>
<B>Definition:</B> This fuNCtion removes the last character of
<TT>STRING</TT> or the last character
of each element in <TT>LIST</TT>.
<BLOCKQUOTE>
<PRE>
$tmp = "1234";
print("chop(\$tmp) returned ", chop($tmp), "\n");
<BR>
</PRE>
</BLOCKQUOTE>
<p>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Tip</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Use <TT>chomp()</TT> (with <TT>$/</TT> set to "\n") rather than <TT>chop()</TT> if you are not sure that the string has a trailing newline.
</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 successfully
changed.<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 more
information.
<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 process
to <TT>DIR_NAME</TT>. Which means
that 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 handle
refers to a pipe the Perl program waits until the process being
piped to has finished.
<BLOCKQUOTE>
<PRE>
open(FILE, "test1.txt");
# some file activity
close(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 closed
correctly, false if not.<BR>
<B>Definition:</B> Closes the directory opened by <TT>opendir()</TT>.
<BLOCKQUOTE>
<PRE>
opendir(DIR, ".");
# some directory activity
closedir(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 no
expression 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 the
database 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 undefined
null value and a defined null value. Some fuNCtions return undefined
null to indicate errors, while others return a defined null to
indicate a particular result (use a comparison with the null string
to 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 undefined
value if nothing was deleted.<BR>
<B>Definition:</B> Deletes an entry from an associative array.
<TT>EXPR</TT> is the key for the entry
to 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 exit
value 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> will
be 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.pl
at 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 been
mostly 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 image
or core dump. You can reload the image using undump program. When
reloaded, the program begins execution from the optional label
specified. So it is possible to set up a program which initializes
data structures to <TT>dump()</TT>
after the initialization so that execution is faster when reloading
the 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 associative
array. 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> and
other 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/passwd
file</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">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -