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

📄 ch25.htm

📁 this is a book on pearl , simple example with explanation is given here. it could be beneficial for
💻 HTM
📖 第 1 页 / 共 5 页
字号:
or an empty list. <TT>$proto</TT>is the protocol number.<BR><B>Definition:</B> Looks in the <TT>/etc/protocols</TT>system file for the protocol called <TT>NAME</TT>.<BLOCKQUOTE><PRE>($name, $alias, $proto) = getprotobyname(&quot;IP&quot;);print(&quot;getprotobyname() /etc/proto [$name, $alias, $proto].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getprotobynumberNUMBER">getprotobynumber (NUMBER)</A></H3><P><B>Category:</B> Protocols, UNIX<BR><B>Return Value: </B>in Scalar Context: The protocol name associatedwith <TT>NUMBER</TT>.<BR><B>Return Value in Array Context:</B> (<TT>$name</TT>,<TT>$aliases</TT>, <TT>$proto</TT>)or an empty list.<BR><B>Definition:</B> Looks in the <TT>/etc/protocols</TT>system file for <TT>NUMBER</TT>.<BLOCKQUOTE><PRE>($name, $alias, $proto) = getprotobynumber(0);print(&quot;getprotobynumber() /etc/protocols [$name, $alias, $proto].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getprotoent">getprotoent ( )</A></H3><P><B>Category:</B> Protocols, UNIX<BR><B>Return Value:</B> ARRAY. (<TT>$name</TT>,<TT>$aliases</TT>, <TT>$proto</TT>)or an empty list.<BR><B>Definition:</B> When called repeatedly, <TT>getprotoent()</TT>iterates over the <TT>/etc/protocols</TT>system file.<BLOCKQUOTE><PRE>($name, $alias, $proto) = getprotoent();print(&quot;getprotoent() Closes /etc/protocols [$name, $alias, $proto].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getpwent">getpwent ( )</A></H3><P><B>Category:</B> Password, UNIX<BR><B>Return Value: </B>in Scalar Context: The username.<BR><B>Return Value in Array Context:</B> ARRAY. (<TT>$name</TT>,<TT>$passwd</TT>, <TT>$uid</TT>,<TT>$gid</TT>, <TT>$quota</TT>,<TT>$comment</TT>, <TT>$gcos</TT>,<TT>$dir</TT>, <TT>$shell</TT>)or an empty list.<BR><B>Definition:</B> When called repeatedly, <TT>getpwent()</TT>iterates over the <TT>/etc/passwd</TT>system file.<BLOCKQUOTE><PRE>($name, $pass, $uid, $gid, $quota, $name, $gcos, $dir, $shell) = getpwent();print(&quot;getpwent() /etc/passwd [$dir, $shell].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getpwnamNAME">getpwnam (NAME)</A></H3><P><B>Category:</B> Password, UNIX<BR><B>Return Value: </B>in Scalar Context: The userid of <TT>NAME</TT>.<BR><B>Return Value in Array Context:</B> (<TT>$name,$passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell</TT>)or an empty list.<BR><B>Definition:</B> Looks in the <TT>/etc/passwd</TT>system file for <TT>NAME</TT>.<BLOCKQUOTE><PRE>($name, $pass, $uid, $gid, $quota, $name,     $gcos, $dir, $shell) = getpwnam(&quot;root&quot;);print(&quot;getpwnam() /etc/passwd [$dir, $shell].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getpwuidUID">getpwuid (UID)</A></H3><P><B>Category:</B> Password, UNIX<BR><B>Return Value: </B>in Scalar Context: The username of <TT>UID</TT>.<BR><B>Return Value in Array Context:</B> (<TT>$name</TT>,<TT>$passwd</TT>, <TT>$uid</TT>,<TT>$gid</TT>, <TT>$quota</TT>,<TT>$comment</TT>, <TT>$gcos</TT>,<TT>$dir</TT>, <TT>$shell</TT>)or an empty list.<BR><B>Definition:</B> Looks in the <TT>/etc/passwd</TT>system file for <TT>UID</TT>.<BLOCKQUOTE><PRE>($name, $pass, $uid, $gid, $quota, $name,     $gcos, $dir, $shell) = getpwuid(0);print(&quot;getpwuid() /etc/passwd [$dir, $shell].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getservbynameNAMEPROTOCOL">getservbyname (NAME, PROTOCOL)</A></H3><P><B>Category:</B> Protocol, Service, Socket, UNIX<BR><B>Return Value: </B>in Scalar Context: The port number.<BR><B>Return Value in Array Context:</B> (<TT>$name</TT>,<TT>$aliases</TT>, <TT>$port</TT>,<TT>$proto</TT>) or an empty list.<BR><B>Definition:</B> Gets services by name. Looks in the <TT>/etc/services</TT>system file.<BLOCKQUOTE><PRE>($name, $aliases, $port, $protol) = getservbyname(&quot;tcpmux&quot;, &quot;tcp&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getservbyportPORTNUMBERPROTOCOL">getservbyport (PORT_NUMBER, PROTOCOL)</A></H3><P><B>Category:</B> Protocol, Service, Socket, UNIX<BR><B>Return Value: </B>in Scalar Context: The service name.<BR><B>Return Value in Array Context:</B> (<TT>$name</TT>,<TT>$aliases</TT>, <TT>$port</TT>,<TT>$proto</TT>) or an empty list.<BR><B>Definition:</B> Gets services by port. Looks in the <TT>/etc/services</TT>system file.<BLOCKQUOTE><PRE>($name, $aliases, $port, $protol) = getservbyport(512, &quot;tcp&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getservent">getservent ( )</A></H3><P><B>Category:</B> Protocol, Service, Socket, UNIX<BR><B>Return Value: </B>in Scalar Context: The next service name.<BR><B>Return Value in Array Context:</B> (<TT>$name</TT>,<TT>$aliases</TT>, <TT>$port</TT>,<TT>$proto</TT>) or an empty list.<BR><B>Definition:</B> When called repeatedly, iterates over the <TT>/etc/services</TT>system file.<BLOCKQUOTE><PRE>($name, $aliases, $port, $protol) = getservent();print(&quot;getservent() /etc/servers [$name].\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="getsocknameSOCKET">getsockname (SOCKET)</A></H3><P><B>Category:</B> Sockets<BR><B>Return Value:</B> SCALAR, the packed address of the local endof the socket.<BR><B>Definition:</B> Finds out the address of your script's socket.<BLOCKQUOTE><PRE>$packedAddr = getsockname(S);($family, $port, $localAddr) = unpack('S n a4 x8', $packedAddr);</PRE></BLOCKQUOTE><H3><A NAME="getsockoptSOCKETLEVELOPTNAME">getsockopt (SOCKET, LEVEL, OPTNAME)</A></H3><P><B>Category:</B> Sockets<BR><B>Return Value:</B> SCALAR, the socket option requested or theundefined value.<BR><B>Definition:</B> Gets the value of a specified socket option.<H3><A NAME="globEXPR">glob (EXPR)</A></H3><P><B>Category:</B> File<BR><B>Return Value:</B> ARRAY, the list of files represented by <TT>EXPR</TT>.<BR><B>Definition:</B> Looks for file name that match <TT>EXPR</TT>.You can use wildcards in <TT>EXPR</TT>.<BLOCKQUOTE><PRE>@files = glob(&quot;*.txt&quot;);</PRE></BLOCKQUOTE><H3><A NAME="gmtimeEXPR">gmtime ([EXPR])</A></H3><P><B>Category:</B> Time<BR><B>Return Value: </B>in Scalar Context: A string like 'Sat Jul13 07:34:46 1986' describing <TT>EXPR</TT>.<BR><B>Return Value in Array Context:</B> (<TT>$sec</TT>,<TT>$min</TT>, <TT>$hour</TT>,<TT>$mday</TT>, <TT>$mon</TT>,<TT>$year</TT>, <TT>$wday</TT>,<TT>$ydat</TT>, <TT>$isdst</TT>).<BR><B>Definition:</B> Breaks <TT>EXPR</TT>(a number of seconds siNCe 1st Jan 1970) into a 9-element list.If no argument is used the current time is used. If your systemsupports POSIX time zones, the time returned is localized forthe Greenwich Mean Time time zone. Note that <TT>$mon</TT>ranges from 0..11, <TT>$wday</TT>ranges from 0..6, and <TT>$year</TT>does not handle centuries.<BLOCKQUOTE><PRE>($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) = gmtime();print &quot;gmtime() 19$year-$mon-$mday\n&quot;;</PRE></BLOCKQUOTE><H3><A NAME="grepBLOCKEXPRLIST">grep (BLOCK | EXPR, LIST)</A></H3><P><B>Category:</B> Regular Expressions<BR><B>Return Value: </B>in Scalar Context: The number of times that<TT>BLOCK</TT> or <TT>EXPR</TT>evaluated to true.<BR><B>Return Value in Array Context:</B> A list of the elements of<TT>LIST</TT> that causes <TT>BLOCK</TT>or <TT>EXPR</TT> to evaluate as true.<BR><B>Definition:</B> Evaluates the expression or block for eachof the elements in <TT>LIST</TT>.Think of this fuNCtion as having an internal <TT>foreach</TT>loop. Each element in <TT>LIST</TT>is assigned to <TT>$_</TT> and thenthe block or expression is evaluated. The most common use forthis is with a pattern match operation as the expression, anda list of strings to be processed. You may be tempted to use <TT>grep()</TT>as an easy way to interate over an array as shown in the secondexample below, <I>don't do this</I>. Use the <TT>map()</TT>fuNCtion instead.<BLOCKQUOTE><PRE># Look for all elements that begin with the letter T.@a = ('One', 'Two', 'Three', 'Four', 'Five');print(&quot;grep(), &quot;, grep(/^T/, @a), &quot;\n&quot;);# Print all elements in a list.@a = ('One', 'Two', 'Three', 'Four', 'Five');grep( print(&quot;$_\n&quot;), @a);</PRE></BLOCKQUOTE><H3><A NAME="hexEXPR">hex (EXPR)</A></H3><P><B>Category:</B> Math, String<BR><B>Return Value:</B> SCALAR, the decimal value of <TT>EXPR</TT>.<BR><B>Definition:</B> Converts <TT>EXPR</TT>from hexadecimal to decimal. For example, <TT>hex('FF0')</TT>will return <TT>'4080'</TT>. You canuse the string returned as a number because Perl will automaticallyconvert strings to numbers in numeric contexts.<BLOCKQUOTE><PRE>print(&quot;hex() &quot;, hex(&quot;ff&quot;), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="import">import ( )</A></H3><P><B>Category:</B> Miscellaneous<BR><B>Return Value:</B> None. <BR><B>Definition:</B> This is the only user-defined fuNCtion in thislist. If a module has an <TT>import()</TT>fuNCtion then the <TT>use()</TT> fuNCtionwill call it as the module is being loaded. You can use the <TT>import()</TT>fuNCtion to initialize variables, open files, or do any othersetup work.<H3><A NAME="indexSTRINGSUBSTRINGPOSITION">index (STRING, SUBSTRING, [POSITION])</A></H3><P><B>Category:</B> String<BR><B>Return Value:</B> SCALAR, the position of the first occurreNCeof <TT>SUBSTRING</TT> in <TT>STRING</TT>at or after <TT>POSITION</TT> or -1if not found.<BR><B>Definition:</B> When called repeatedly, you can iterate overall the occurreNCes of <TT>SUBSTRING</TT>in <TT>STRING</TT>. The returned valueis an offset from <TT>$[</TT> (whichis normally zero). If <TT>$[</TT>is altered it will change the way <TT>index()</TT>works as it will start its search from <TT>$[</TT>if no position argument is supplied, and it will return <TT>$[- 1</TT> when there is no match found.<BLOCKQUOTE><PRE>$answer1 = index(&quot;abcdefghijiklmdef:-)&quot;, &quot;def&quot;);$answer2 = index(&quot;abcdefghijiklmdef&quot;, &quot;def&quot;, $answer1 + 3);print(&quot;index() def is at $answer1 and next at $answer2\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="intEXPR">int ([EXPR])</A></H3><P><B>Category:</B> Math<BR><B>Return Value:</B> SCALAR, the integer portion of <TT>EXPR</TT>.<BR><B>Definition:</B> Chops of any fractional part of <TT>EXPR</TT>or <TT>$_</TT> if no expression isspecified.<BR>For example, <TT>int(21.45)</TT> wouldreturn <TT>21</TT>.<BLOCKQUOTE><PRE>print(&quot;int() &quot;, int(345.678), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="ioctlFILEHANDLEFUNCTIONSCALAR">ioctl (FILEHANDLE, FUNCTION, SCALAR)</A></H3><P><B>Category:</B> File, UNIX<BR><B>Return Value:</B> SCALAR, true if successful; false if notand the undefined value in some cases.<BR><B>Definition:</B> Controls Input/Output operations, mainly usedfor terminals. It calls the UNIX <TT>ioctl()</TT>fuNCtion with the specified parameters. Returns undefined if theoperating system returns -1. Returns string &quot;0 but true&quot;if the operating system returns 0. Otherwise returns the valuereturned by the operating system. You can find more informationabout <TT>ioctl()</TT> in section2 of the UNIX manual pages.<H3><A NAME="joinEXPRLIST">join (EXPR, LIST)</A></H3><P><B>Category:</B> Array, String<BR><B>Return Value:</B> SCALAR, a string with each element of <TT>LIST</TT>alternating with <TT>EXPR</TT>.<BR><B>Definition:</B> CoNCatenates all of the elements of <TT>LIST</TT>together with <TT>EXPR</TT> as theglue. For example, <TT>join('!', ('QQ', 'AA'))</TT>will return <TT>'QQ!AA'</TT>.<BLOCKQUOTE><PRE>@listone = (0, 1, 2, 3);print(&quot;join() &quot;, join(&quot;-&quot;,@listone), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="keysHASH">keys (HASH)</A></H3><P><B>Category:</B> Array, Hash <BR><B>Return Value: </B>in Scalar Context: The number of keys and,therefore, the number of entries in <TT>HASH</TT>.<BR><B>Return Value in Array Context:</B> All of the keys to <TT>HASH</TT>in no particular order.<BR><B>Definition:</B> Gets a list of all keys in <TT>HASH</TT>.The returned list is ordered by the internal storage requirements,so it is often useful to use the <TT>sort()</TT>fuNCtion before processing. For example, <TT>sort(keys(%hash))</TT>.<BLOCKQUOTE><PRE>%hash = ('One' =&gt; 1, 'Two' =&gt; 2, 'Three' =&gt; 3, 'Four' =&gt; 4);print(&quot;keys() &quot;, join(&quot;-&quot;, keys(%hash)), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="killSIGNALLIST">kill (SIGNAL, LIST)</A></H3><P><B>Category:</B> Process<BR><B>Return Value:</B> SCALAR, the number of processes successfullysignaled.<BR><B>Definition:</B> Sends <TT>SIGNAL</TT>to the processes identified by <TT>LIST</TT>.If <TT>SIGNAL</TT> is negative thenprocess groups are killed instead.<H3><A NAME="lcEXPR">lc (EXPR)</A></H3><P><B>Category:</B> String<BR><B>Return Value:</B> SCALAR, a copy of <TT>EXPR</TT>with all letters in lowercase.<BR><B>Definition:</B> Creates a copy of <TT>EXPR</TT>with all letters in lowercase.<BLOCKQUOTE><PRE>print(&quot;lc() &quot;, lc(&quot;ABCDef&quot;), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="lcfirstEXPR">lcfirst (EXPR)</A></H3><P><B>Category:</B> String<BR><B>Return Value:</B> SCALAR, a copy of <TT>EXPR</TT>with the first letter in lowercase.<BR><B>Definition:</B> Creates a copy of <TT>EXPR</TT>with the first letter in lowercase.<BLOCKQUOTE><PRE>print(&quot;lcfirst() &quot;, lcfirst(&quot;ABCDef&quot;), &quot;\n&quot;);</PRE></BLOCKQUOTE><H3><A NAME="lengthE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -