📄 ch25.htm
字号:
<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 ofadditional modules each with its own additional fuNCtions. Thisappendix lists all the standard fuNCtions alphabetically for refereNCe.<P>Each fuNCtion has been assigned one or more categories to aidyou in finding the fuNCtion that you need. This is a very roughcategorization, as many fuNCtions might overlap in any categoryscheme.<P>For each fuNCtion, the needed parameters are shown. The parametersare described in the text where the meaning is not obvious.<P>Quite a few of Perl's fuNCtion mirror those available to C programmersunder the UNIX system and are at least moderately complicatedto use. Please look in the UNIX documentation for additional informationif you're interested in the socket, shared memory, or semaphorefuNCtions.<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 isspecified.<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 clientor false if a problem occurred.<BR><B>Definition:</B> Accepts a socket connection from clients waitingfor 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 beforethe 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 Perlto trap such signals and call specific signal handling subroutines.See <A HREF="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 expressionis 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 anerror 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 ifnot.<BR><B>Definition:</B> On systems which distinguish between text andbinary files (like Windows 95 and Windows NT) this fuNCtion forcesbinary mode treatment of <TT>FILEHANDLE</TT>.In systems which do make the distiNCtion, text files have theend of line characters-carriage return (<TT>'\r'</TT>)and linefeed(<TT>'\n'</TT>)-automaticallytranslated into the UNIX end-of-line character (<TT>'\n'</TT>)when reading from the file and when writing to the file. Binarymode files do not have this automatic transformation. See "Example:Binary Files" in <A HREF="ch9.htm" >Chapter 9</A> "Using Files," formore 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 variableto <TT>CLASSNAME</TT>. It is usedto assign a class name to the refereNCed variable, thus changingthe string returned by the <TT>ref()</TT>fuNCtion. If <TT>CLASSNAME</TT> isnot specified, the name of the current package is used. See Chapter8, "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 currentcode has been called as a subroutine (this iNCludes code whichis iNCluded using a <TT>require()</TT>or an <TT>eval() call)</TT>. Otherwise,false.<BR><B>Return Value in Array Context:</B> ARRAY, contains detailsof 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 scopeof 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 directoryspecified. If no argument is given changes to the home directoryof 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> isan octal number representing file permissions which are appliedto all the files in <TT>LIST</TT>.<BLOCKQUOTE><PRE>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 stringsupon which to perform this operation. When given no argumentsthe 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 characterof 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -