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

📄 ch25.htm

📁 prrl 5 programs codes in the book
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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 = &quot;AAAAA!\n&quot;;

print(&quot;chomp(\$temp) returned &quot;, chomp($temp), &quot;.\n&quot;);

</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 = &quot;1234&quot;;

print(&quot;chop(\$tmp) returned &quot;, chop($tmp), &quot;\n&quot;);

<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 &quot;\n&quot;) 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, &quot;test1.txt&quot;);

</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, &quot;ASCII Table&quot; 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(&quot;/usr/~waters&quot;);<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, &quot;test1.txt&quot;);

# 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, &quot;.&quot;);

# 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(&quot;Password&quot;,&quot;TR&quot;);

</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(&quot;exists.\n&quot;) if defined(@iexist);

print(&quot;does not exist.\n&quot;) 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' =&gt; 'One', 'Feb' =&gt; 'Two', 'Mar' =&gt; '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 &quot;at test.pl

at line 10&quot; will be appended to the end.

<BLOCKQUOTE>

<PRE>

die(&quot;Something fatal has happened and the script must die!&quot;);

</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' =&gt; 'One', '2' =&gt; 'Two', '3' =&gt; 'Three');

while (($key, $value) = each(%NumberWord)) {

    print(&quot;$key: $value\n&quot;);

}

</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(&quot;lyNCh&quot;);

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 + -