📄 ch25.htm
字号:
<LI><A HREF="#undefEXPR">
undef ([EXPR])</A>
<LI><A HREF="#unlinkLIST">
unlink (LIST)</A>
<LI><A HREF="#unpackTEMPLATEEXPR">
unpack (TEMPLATE, EXPR)</A>
<LI><A HREF="#unshiftARRAYLIST">
unshift (ARRAY, LIST)</A>
<LI><A HREF="#untieVARIABLE">
untie (VARIABLE)</A>
<LI><A HREF="#utimeAccESSTIMEMODIFICATIONTIMELIST">
utime (AccESS_TIME, MODIFICATION_TIME, LIST)</A>
<LI><A HREF="#valuesHASH">
values (HASH)</A>
<LI><A HREF="#vecEXPROFFSETNUMBITS">
vec (EXPR, OFFSET, NUM_BITS)</A>
<LI><A HREF="#wait">
wait ( )</A>
<LI><A HREF="#waitpidPIDFLAGS">
waitpid (PID, FLAGS)</A>
<LI><A HREF="#wantarray">
wantarray ( )</A>
<LI><A HREF="#warnLIST">
warn ([LIST])</A>
<LI><A HREF="#writeFILEHANDLEEXPR">
write ([FILEHANDLE | EXPR])</A>
</UL>
</UL>
<HR>
<P>
Perl has a large number of fuNCtions and an even wider range of
additional modules each with its own additional fuNCtions. This
appendix lists all the standard fuNCtions alphabetically for refereNCe.
<P>
Each fuNCtion has been assigned one or more categories to aid
you in finding the fuNCtion that you need. This is a very rough
categorization, as many fuNCtions might overlap in any category
scheme.
<P>
For each fuNCtion, the needed parameters are shown. The parameters
are described in the text where the meaning is not obvious.
<P>
Quite a few of Perl's fuNCtion mirror those available to C programmers
under the UNIX system and are at least moderately complicated
to use. Please look in the UNIX documentation for additional information
if you're interested in the socket, shared memory, or semaphore
fuNCtions.
<H2><A NAME="FuNCtionsbyCategory"><FONT SIZE=5 COLOR=#FF0000>
FuNCtions by Category</FONT></A></H2>
<P>
This section listed Perl's fuNCtions by category.
<UL>
<LI><B>Array:</B> <TT>chomp</TT>,
<TT>join</TT>, <TT>keys</TT>,
<TT>map</TT>, <TT>pop</TT>,
<TT>push</TT>, <TT>reverse</TT>,
<TT>shift</TT>, <TT>sort</TT>,
<TT>splice</TT>, <TT>split</TT>,
<TT>unshift</TT>, <TT>values</TT>
<LI><B>Database:</B> <TT>dbmclose</TT>,
<TT>dbmopen</TT>
<LI><B>Directory:</B> <TT>chdir</TT>,
<TT>closedir</TT>, <TT>mkdir</TT>,
<TT>opendir</TT>, <TT>readdir</TT>,
<TT>rewinddir</TT>, <TT>rmdir</TT>,
<TT>seekdir</TT>, <TT>telldir</TT>
<LI><B>File:</B> <TT>binmode</TT>,
<TT>chdir</TT>, <TT>chmod</TT>,
<TT>chown</TT>, <TT>chroot</TT>,
<TT>close</TT>, <TT>eof</TT>,
<TT>fNCtl</TT>, <TT>fileno</TT>,
<TT>flock</TT>, <TT>getc</TT>,
<TT>glob</TT>, <TT>ioctl</TT>,
<TT>link</TT>, <TT>lstat</TT>,
<TT>open</TT>, <TT>print</TT>,
<TT>printf</TT>, <TT>read</TT>,
<TT>readdir</TT>, <TT>readlink</TT>,
<TT>rename</TT>, <TT>rmdir</TT>,
<TT>seek</TT>, <TT>select</TT>,
<TT>stat</TT>, <TT>symlink</TT>,
<TT>sysopen</TT>, <TT>sysread</TT>,
<TT>syswrite</TT>, <TT>tell</TT>,
<TT>truNCate</TT>, <TT>umask</TT>,
<TT>unlink</TT>, <TT>utime</TT>,
<TT>write</TT>
<LI><B>Group:</B> <TT>endgrent</TT>,
<TT>getgrent</TT>, <TT>getgrgid</TT>,
<TT>getgrname</TT>, <TT>getpgrp</TT>,
<TT>setgrent</TT>, <TT>setpgrp</TT>
<LI><B>Hash:</B> <TT>delete</TT>,
<TT>each</TT>, <TT>exists</TT>,
<TT>keys</TT>, <TT>values</TT>
<LI><B>Host:</B> <TT>endhostent</TT>,
<TT>gethostbyaddr</TT>, <TT>gethostbyname</TT>,
<TT>sethostent</TT>
<LI><B>Input:</B> <TT>getc</TT>, <TT>read</TT>,
<TT>sysread</TT>
<LI><B>Inter-process Communication:</B> <TT>msgctl</TT>,
<TT>msgget</TT>, <TT>msgrcv</TT>,
<TT>msgsnd</TT>, <TT>pipe</TT>,
<TT>semctl</TT>, <TT>semget</TT>,
<TT>semop</TT>, <TT>shmctl</TT>,
<TT>shmget</TT>, <TT>shmread</TT>,
<TT>shmwrite</TT>
<LI><B>Math:</B> <TT>abs</TT>, <TT>atan2</TT>,
<TT>cos</TT>, <TT>exp</TT>,
<TT>hex</TT>, <TT>int</TT>,
<TT>log</TT>, <TT>oct</TT>,
<TT>rand</TT>, <TT>sin</TT>,
<TT>sqrt</TT>, <TT>srand</TT>
<LI><B>Message Queues:</B> <TT>msgctl</TT>,
<TT>msgget</TT>, <TT>msgrcv</TT>,
<TT>msgsnd</TT>
<LI><B>Miscellaneous:</B> <TT>bless</TT>,
<TT>defined</TT>, <TT>do</TT>,
<TT>eval</TT>, <TT>formline</TT>,
<TT>import</TT>, <TT>ref</TT>,
<TT>scalar</TT>, <TT>syscall</TT>,
<TT>tie</TT>, <TT>tied</TT>,
<TT>undef</TT>, <TT>untie</TT>,
<TT>wantarray</TT>
<LI><B>Network:</B> <TT>endnetent</TT>,
<TT>getnetbyaddr</TT>, <TT>getnetbyname</TT>,
<TT>getnetent</TT>, <TT>setnetent</TT>
<LI><B>Output:</B> <TT>die</TT>, <TT>print</TT>,
<TT>printf</TT>, <TT>syswrite</TT>,
<TT>warn</TT>, <TT>write</TT>
<LI><B>Password:</B> <TT>endpwent</TT>,
<TT>getpwent</TT>, <TT>getpwname</TT>,
<TT>getpwuid</TT>, <TT>setpwent</TT>
<LI><B>Process:</B> <TT>alarm</TT>,
<TT>die</TT>, <TT>dump</TT>,
<TT>exec</TT>, <TT>exit</TT>,
<TT>fork</TT>, <TT>getlogin</TT>,
<TT>getpgrp</TT>, <TT>getppid</TT>,
<TT>getpriority</TT>, <TT>kill</TT>,
<TT>setpriority</TT>, <TT>sleep</TT>,
<TT>system</TT>, <TT>times</TT>,
<TT>umask</TT>, <TT>wait</TT>,
<TT>waitpid</TT>
<LI><B>Protocol:</B> <TT>endprotent</TT>,
<TT>getprotobyname</TT>, <TT>getprotobynumber</TT>,
<TT>getprotoent</TT>, <TT>getservbyname</TT>,
<TT>getservbyport</TT>, <TT>getservent</TT>,
<TT>setprotoent</TT>
<LI><B>Regular Expression:</B> <TT>grep</TT>,
<TT>pos</TT>, <TT>quotemeta</TT>,
<TT>reset</TT>, <TT>split</TT>,
<TT>study</TT>
<LI><B>Scope:</B> <TT>caller</TT>,
<TT>local</TT>, <TT>my</TT>
<LI><B>Service:</B> <TT>endservent</TT>,
<TT>getservbyname</TT>, <TT>getservbyport</TT>,
<TT>getservent</TT>, <TT>setservent</TT>
<LI><B>Socket:</B> <TT>accept</TT>,
<TT>bind</TT>, <TT>connect</TT>,
<TT>gethostbyaddr</TT>, <TT>gethostbyname</TT>,
<TT>gethostent</TT>, <TT>getpeername</TT>,
<TT>getservbyname</TT>, <TT>getservbyport</TT>,
<TT>getservent</TT>, <TT>getsockname</TT>,
<TT>getsockopt</TT>, <TT>listen</TT>,
<TT>recv</TT>, <TT>select</TT>,
<TT>send</TT>, <TT>setsockopt</TT>,
<TT>shutdown</TT>, <TT>socket</TT>,
<TT>socketpair</TT>
<LI><B>String:</B> <TT>chop</TT>,
<TT>chr</TT>, <TT>crypt</TT>,
<TT>hex</TT>, <TT>index</TT>,
<TT>join</TT>, <TT>lc</TT>,
<TT>lcfirst</TT>, <TT>length</TT>,
<TT>oct</TT>, <TT>pack</TT>,
<TT>q</TT>, <TT>qq</TT>,
<TT>quotemeta</TT>, <TT>qw</TT>,
<TT>qx</TT>, <TT>reverse</TT>,
<TT>rindex</TT>, <TT>split</TT>,
<TT>sprintf</TT>, <TT>substr</TT>,
<TT>uc</TT>, <TT>ucfirst</TT>,
<TT>unpack</TT>, <TT>vec</TT>
<LI><B>Time:</B> <TT>gmtime</TT>,
<TT>localtime</TT>, <TT>time</TT>
<LI><B>UNIX:</B> <TT>chmod</TT>, <TT>chown</TT>,
<TT>chroot</TT>, <TT>dump</TT>,
<TT>endgrent</TT>, <TT>endhostent</TT>,
<TT>endnetent</TT>, <TT>endprotent</TT>,
<TT>endpwent</TT>, <TT>endservent</TT>,
<TT>fNCtl</TT>, <TT>fork</TT>,
<TT>getgrent</TT>, <TT>getgrgid</TT>,
<TT>getgrname</TT>, <TT>gethostent</TT>,
<TT>getlogin</TT>, <TT>getnetent</TT>,
<TT>getpgrp</TT>, <TT>getppid</TT>,
<TT>getpriority</TT>, <TT>getprotobyname</TT>,
<TT>getprotobynumber</TT>, <TT>getprotoent</TT>,
<TT>getpwent</TT>, <TT>getpwname</TT>,
<TT>getpwuid</TT>, <TT>getservbyname</TT>,
<TT>getservbyport</TT>, <TT>getservent</TT>,
<TT>ioctl</TT>, <TT>link</TT>,
<TT>lstat</TT>, <TT>readlink</TT>,
<TT>select</TT>, <TT>setgrent</TT>,
<TT>sethostent</TT>, <TT>setnetent</TT>,
<TT>setpgrp</TT>, <TT>setpriority</TT>,
<TT>setprotoent</TT>, <TT>setpwent</TT>,
<TT>setservent</TT>, <TT>sleep</TT>,
<TT>syscall</TT>, <TT>times</TT>,
<TT>umask</TT>, <TT>wait</TT>,
<TT>waitpid</TT>
</UL>
<H2><A NAME="FuNCtionsbyName"><FONT SIZE=5 COLOR=#FF0000>
FuNCtions by Name</FONT></A></H2>
<P>
Here is the list of Perl's fuNCtion sorted by name.
<H3><A NAME="absEXPR">
abs([EXPR])</A></H3>
<P>
<B>Category:</B> Math<BR>
<B>Return Value:</B> scalar, the absolute value of <TT>EXPR</TT>
or <TT>$_</TT> if no expression is
specified.<BR>
<B>Definition:</B> Calculates an absolute value. For example,
<TT>abs(-10)</TT> is 10.
<H3><A NAME="acceptNEWSOCKETGENERICSOCKET">
accept (NEWSOCKET, GENERICSOCKET)</A></H3>
<P>
<B>Category:</B> Socket<BR>
<B>Return Value:</B> SCALAR, the packed address of the client
or false if a problem occurred.<BR>
<B>Definition:</B> Accepts a socket connection from clients waiting
for a connection. The <TT>GENERICSOCKET</TT>
parameter must have already been opened using the <TT>socket()</TT>
fuNCtion. You can find more information about <TT>accept()</TT>
in section 2 of the UNIX manual pages.
<H3><A NAME="alarmNUMOFSECONDS">
alarm (NUM_OF_SECONDS)</A></H3>
<P>
<B>Category:</B> Process<BR>
<B>Return Value:</B> SCALAR, the number of seconds remaining before
the previous alarm was due to go off.<BR>
<B>Definition:</B> Sends a SIGALARM to your script after NUM_OF_SECONDS.
A call with NUM_OF_SECONDS equal to zero caNCels the current alarm.
You can find more information about <TT>alarm()</TT>
in section 3 of the UNIX manual pages. It is poss-ible for Perl
to trap such signals and call specific signal handling subroutines.
See <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and Signals."
<BLOCKQUOTE>
<PRE>
alarm(10);
</PRE>
</BLOCKQUOTE>
<H3><A NAME="atanEXPR">
atan2 ([EXPR])</A></H3>
<P>
<B>Category:</B> Math<BR>
<B>Return Value:</B> SCALAR, the arc tangent of <TT>EXPR</TT>
or of <TT>$_</TT> if no expression
is specified.<BR>
<B>Definition:</B> Calculates an arc tangent.
<BLOCKQUOTE>
<PRE>
$arcTangent = atan2(60,2);
</PRE>
</BLOCKQUOTE>
<H3><A NAME="bindSOCKETNAME">
bind (SOCKET, NAME)</A></H3>
<P>
<B>Category:</B> Socket<BR>
<B>Return Value:</B> SCALAR, the socket handle or false if an
error occurred.<BR>
<B>Definition:</B> Binds a network address to the socket handle.
You can find more information about <TT>bind()</TT>
in section 2 of the UNIX manual pages.
<H3><A NAME="binmodeFILEHANDLE">
binmode (FILEHANDLE)</A></H3>
<P>
<B>Category:</B> File<BR>
<B>Return Value:</B> SCALAR, true if successful or undefined if
not.<BR>
<B>Definition:</B> On systems which distinguish between text and
binary files (like Windows 95 and Windows NT) this fuNCtion forces
binary mode treatment of <TT>FILEHANDLE</TT>.
In systems which do make the distiNCtion, text files have the
end of line characters-carriage return (<TT>'\r'</TT>)
and linefeed(<TT>'\n'</TT>)-automatically
translated into the UNIX end-of-line character (<TT>'\n'</TT>)
when reading from the file and when writing to the file. Binary
mode files do not have this automatic transformation. See "Example:
Binary Files" in <A HREF="ch9.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch9.htm" >Chapter 9</A> "Using Files," for
more information.
<BLOCKQUOTE>
<PRE>
open(FILE, "file.dat");
binmode(FILE);
</PRE>
</BLOCKQUOTE>
<H3><A NAME="blessREFERENCECLASSNAME">
bless (REFERENCE, [CLASSNAME])</A></H3>
<P>
<B>Category:</B> Object<BR>
<B>Return Value:</B> SCALAR, a refereNCe to the blessed object.
<BR>
<B>Definition:</B> Changes the type of the refereNCed variable
to <TT>CLASSNAME</TT>. It is used
to assign a class name to the refereNCed variable, thus changing
the string returned by the <TT>ref()</TT>
fuNCtion. If <TT>CLASSNAME</TT> is
not specified, the name of the current package is used. See Chapter
8, "RefereNCes," for more information.
<BLOCKQUOTE>
<PRE>
$temp = { }
bless $temp, 'ATMPCLASS';
print("bless() \$temp is now has type ", ref($temp), "\n");
<BR>
</PRE>
</BLOCKQUOTE>
<p>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Tip</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Always specify the <TT>CLASSNAME</TT> parameter if the blessing fuNCtion might be inherited.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<H3><A NAME="callerEXPR">
caller ([EXPR])</A></H3>
<P>
<B>Category:</B> Scope<BR>
<B>Return Value:</B> in Scalar Context: SCALAR, true if the current
code has been called as a subroutine (this iNCludes code which
is iNCluded using a <TT>require()</TT>
or an <TT>eval() call)</TT>. Otherwise,
false.<BR>
<B>Return Value in Array Context:</B> ARRAY, contains details
of the calling context comprising the package name, file name,
and line of the call.<BR>
<B>Definition:</B> This fuNCtion is used to test the current scope
of a subroutine call.
<BLOCKQUOTE>
<PRE>
sub testcaller {
($package, $file, $line) = caller;
print("caller() Package=$package File=$file Line=$line\n");
}
testcaller();
</PRE>
</BLOCKQUOTE>
<H3><A NAME="chdirDIRNAME">
chdir ([DIRNAME])</A></H3>
<P>
<B>Category:</B> Directory<BR>
<B>Return Value:</B> SCALAR, true if successful, false otherwise.
<BR>
<B>Definition:</B> Changes the current directory to the directory
specified. If no argument is given changes to the home directory
of the current user.
<BLOCKQUOTE>
<PRE>
chdir("/") ? print("It worked.\n") : print("It didn't work.\n");
</PRE>
</BLOCKQUOTE>
<H3><A NAME="chmodMODELIST">
chmod (MODE, LIST)</A></H3>
<P>
<B>Category:</B> File, UNIX<BR>
<B>Return Value:</B> SCALAR, the number of files changed.<BR>
<B>Definition:</B> <TT>MODE</TT> is
an octal number representing file permissions which are applied
to all the files in <TT>LIST</TT>.
<BLOCKQUOTE>
<PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -