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

📄 ch25.htm

📁 prrl 5 programs codes in the book
💻 HTM
📖 第 1 页 / 共 5 页
字号:

endservent ( )</A></H3>

<P>

<B>Category:</B> Server, UNIX<BR>

<B>Return Value:</B> SCALAR, true if successful, false if not.

<BR>

<B>Definition:</B> Closes the <TT>/etc/servers</TT>

file used by <TT>getservent()</TT>

and related fuNCtions.

<BLOCKQUOTE>

<PRE>

($name, $aliases, $port, $protocol) = getservent();

endservent();

</PRE>

</BLOCKQUOTE>

<H3><A NAME="eofFILEHANDLE">

eof ([FILEHANDLE])</A></H3>

<P>

<B>Category:</B> File<BR>

<B>Return Value:</B> SCALAR, true if the next read on <TT>FILEHANDLE</TT>

will be at the end of file, false if not.<BR>

<B>Definition:</B> Tests for the end of a file. This is done by

reading the next character and then undoing this operation (so

is only suitable on files where this can be done safely). If no

argument is supplied the file tested is the last file which was

read. If the empty list is supplied then a pseudo file is created

of the files listed on the command line. This lets you test for

the end of the last file on the command line.

<BLOCKQUOTE>

<PRE>

open(FILE, &quot;test1.txt&quot;);

# some file activity

print(&quot;eof() returned &quot;, eof(FILE) ? &quot;TRUE&quot; : &quot;FALSE&quot;, &quot;\n&quot;);

close(FILE);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="evalEXPRBLOCK">

eval ([EXPR | BLOCK])</A></H3>

<P>

<B>Category:</B> Miscellaneous<BR>

<B>Return Value:</B> The undefined value if a syntax error, a

runtime error, or a <TT>die()</TT>

fuNCtion occurs. Otherwise, the return value is the value of <TT>EXPR</TT>

or the last statement in <TT>BLOCK</TT>.

The return value can be any type.<BR>

<B>Definition:</B> Treats the expression like a Perl program and

executes it. As the context of this execution is the same as that

of the script itself, variable definitions and subroutine definitions

persist. Syntax errors, runtime errors, and execution of the <TT>die()</TT>

fuNCtion are trapped and an undefined result is returned. If such

an error does occur <TT>$@</TT> is

set. <TT>$@</TT> will be equal to

a defined null string if no errors are found. If no expression

is supplied, <TT>$_</TT> is the default

argument. If the block syntax is used then the expressions in

the block are evaluated only oNCe within the script (which may

be more efficient for certain situations).<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Tip</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

<TT>eval()</TT> traps possible error conditions which would otherwise crash a program and so can be used to test if certain features are available which would cause runtime errors if used when not available. See <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, 
&quot;Handling Errors and Signals,&quot; for more information.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<BLOCKQUOTE>

<PRE>

$answer = 3;

eval(&quot;$answer = ;&quot;);

if ($@ eq &quot;&quot;) {

    print(&quot;eval() returned success.\n&quot;);

}

else {

    print(&quot;eval() error: $@&quot;);

}

</PRE>

</BLOCKQUOTE>

<H3><A NAME="execLIST">

exec (LIST)</A></H3>

<P>

<B>Category:</B> Process<BR>

<B>Return Value:</B> None.<BR>

<B>Definition:</B> This fuNCtion passes control from the script

to an external system command. <B>There is no return from this

call.</B> Note that <TT>system()</TT>

calls external commands and does return.

<BLOCKQUOTE>

<PRE>

exec(&quot;cat /etc/motd&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="existsEXPR">

exists (EXPR)</A></H3>

<P>

<B>Category:</B> Hash<BR>

<B>Return Value:</B> SCALAR, true if <TT>EXPR</TT>

is an entry in a hash, false if not.<BR>

<B>Definition:</B> Tests whether a given key value exists in an

associative array.

<BLOCKQUOTE>

<PRE>

%test = ( 'One' =&gt; '1', 'Two' =&gt; '2');

if (exists($test{'One'})) {

    print(&quot;exists() returned success.\n&quot;);

}

else {

    print(&quot;exists() returned an error.\n&quot;);

}

</PRE>

</BLOCKQUOTE>

<H3><A NAME="exitEXPR">

exit ([EXPR])</A></H3>

<P>

<B>Category:</B> Process<BR>

<B>Return Value:</B> None.<BR>

<B>Definition:</B> Evaluates <TT>EXPR</TT>

and exits the program with that value as the exit code. The default

value for the exit code is 0 if no argument is supplied. If an

<TT>END</TT> block <BR>

has been defined, it will be called. Also, object destructors

may be called before the process truly ends.

<BLOCKQUOTE>

<PRE>

exit(16);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="expEXPR">

exp ([EXPR])</A></H3>

<P>

<B>Category:</B> Math<BR>

<B>Return Value:</B> SCALAR, the natural log base (e) to the power

of <TT>EXPR</TT>.<BR>

<B>Definition:</B> Returns the natural log base (e) to the power

of <TT>EXPR</TT>. If no parameter

is specified, <TT>$_</TT> is used.

<BLOCKQUOTE>

<PRE>

print &quot;exp() e**1 is &quot;, exp(1), &quot;\n&quot;;

</PRE>

</BLOCKQUOTE>

<H3><A NAME="fcntlFILEHANDLEFUNCTIONPACKEDFLAGS">

fcntl (FILEHANDLE, FUNCTION, PACKED_FLAGS)</A></H3>

<P>

<B>Category:</B> File, UNIX<BR>

<B>Return Value:</B> None.<BR>

<B>Definition:</B> In Perl 5 use the <TT>fntcl</TT>

module. In Perl 4 there should be some mechanism for linking the

perl fuNCtions to the system fuNCtions which is usually executed

when Perl is installed. See the <TT>perlfuNC</TT>

man page for more information.

<H3><A NAME="filenoFILEHANDLE">

fileno (FILEHANDLE)</A></H3>

<P>

<B>Category:</B> File<BR>

<B>Return Value:</B> SCALAR, the file descriptor for <TT>FILEHANDLE</TT>.

<BR>

<B>Definition:</B> Returns the file descriptor given a file handle.

File descriptors are useful when using bitmaps for the <TT>select()</TT>

fuNCtion.

<BLOCKQUOTE>

<PRE>

print(&quot;fileno() &quot;, fileno(FILE), &quot;\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="flockFILEHANDLEOPERATIONFLAGS">

flock (FILEHANDLE, OPERATION_FLAGS)</A></H3>

<P>

<B>Category:</B> File<BR>

<B>Return Value:</B> SCALAR, true if successful, false if not.

<BR>

<B>Definition:</B> Lets you access file locks. You can place an

exclusive lock, place a shared lock, or remove locks. You can

find more information about <TT>flock()</TT>

in section 2 of the UNIX manual pages.

<H3><A NAME="fork">

fork ( )</A></H3>

<P>

<B>Category:</B> Process UNIX<BR>

<B>Return Value:</B> SCALAR, the pid of the child process or <TT>undef</TT>

is unsuccessful.<BR>

<B>Definition:</B> Starts a child process. Both child and parent

processes start executing the line of code immediately following

the <TT>fork()</TT> call. You can

find more information about <TT>fork()</TT>

in section 2 of the UNIX manual pages.

<H3><A NAME="formlinePICTURELIST">

formline (PICTURE, LIST)</A></H3>

<P>

<B>Category:</B> Miscellaneous<BR>

<B>Return Value:</B> None.<BR>

<B>Definition:</B> This internal fuNCtion is used by the format

mechanism. It allows direct manipulation of the format process

by adding values to the format accumulator (<TT>$^A</TT>).

For more information about formats, see <A HREF="ch11.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch11.htm" >Chapter 11</A>, &quot;Creating

Reports.&quot;

<H3><A NAME="getcFILEHANDLE">

getc ([FILEHANDLE])</A></H3>

<P>

<B>Category:</B> File, Input<BR>

<B>Return Value:</B> SCALAR, the inputted character. Null if at

end of file.<BR>

<B>Definition:</B> Returns the next character <TT>FILEHANDLE</TT>

or <TT>STDIN</TT> if no filehandle

is specified.

<BLOCKQUOTE>

<PRE>

open(FILE, &quot;/etc/motd&quot;);

print &quot;getc() &quot;, getc(FILE), &quot;\n&quot;;

close(FILE);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getgrent">

getgrent ( )</A></H3>

<P>

<B>Category:</B> Group, UNIX<BR>

<B>Return Value: </B>in Scalar Context : Returns the next group

name or the undefined value if no more groups or an error occurred.

<BR>

<B>Return Value in Array Context :</B> (<TT>$name,

$passwd, $gid, $members</TT>) or an empty list.<BR>

<B>Definition:</B> Returns information about groups taken from

the <TT>/etc/group</TT> system file.

If called repeatedly, it will iterate through the entries in the

<TT>/etc/group</TT> file.

<BLOCKQUOTE>

<PRE>

($name, $pw, $gid, @members) = getgrent();

print(&quot;getgrent() Examines /etc/group [$name,$gid] file.\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getgrgidGID">

getgrgid (GID)</A></H3>

<P>

<B>Category:</B> Group, UNIX<BR>

<B>Return Value: </B>in Scalar Context: The next group name that

belongs to <TT>GID</TT>.

<P>

<B>Return Value in Array Context:</B> (<TT>$name,

$passwd, $gid, $members</TT>) or an empty list.<BR>

<B>Definition:</B> Returns information about groups taken from

the <TT>/etc/group</TT> system file.

<BLOCKQUOTE>

<PRE>

($grname, $grpw, $gid, @members) = getgrgid(0);

print(&quot;getgrgid() Returns group name given GID [$grname]\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getgrnameNAME">

getgrname (NAME)</A></H3>

<P>

<B>Category:</B> Group, UNIX<BR>

<B>Return Value: </B>in Scalar Context: The next group id that

belongs to <TT>NAME</TT>.<BR>

<B>Return Value in Array Context:</B> (<TT>$name,

$passwd, $gid, $members</TT>) or an empty list.<BR>

<B>Definition:</B> Returns information about groups taken from

the <TT>/etc/group</TT> system file.

<BLOCKQUOTE>

<PRE>

($grname, $grpw, $gid, @members) = getgrnam(&quot;root&quot;);

print(&quot;getgrnam() Returns group GID given name [$gid]\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="gethostbyaddrADDRESSAFINIT">

gethostbyaddr (ADDRESS, AF_INIT)</A></H3>

<P>

<B>Category:</B> Host, Socket<BR>

<B>Return Value: </B>in Scalar Context: Name of host addressed

by <TT>ADDRESS</TT> or undefined if

the host could not be found.<BR>

<B>Return Value in Array Context:</B> (<TT>$name</TT>,

<TT>$aliases</TT>, <TT>$addrtype</TT>,

<TT>$length</TT>, <TT>@addrs</TT>)

or an empty list.<BR>

<B>Definition:</B> Looks in the <TT>/etc/hosts</TT>

system file or checks a Domain Name Server for a server with <TT>ADDRESS</TT>.

The value for <TT>AF_INIT</TT> is

always 2.

<BLOCKQUOTE>

<PRE>

use Socket;

$addr = pack('C4', (140,203,7,103));

($name, $alias, $addrtype, $length, @addrs) = gethostbyaddr($addr, AF_INET);

print(&quot;gethostbyaddr() [$alias].\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="gethostbynameNAMEPROTOCOL">

gethostbyname (NAME, [PROTOCOL])</A></H3>

<P>

<B>Category:</B> Host, Socket<BR>

<B>Return Value: </B>in Scalar Context: Address of the host called

<TT>NAME</TT> or undefined if the

host could not be found.<BR>

<B>Return Value in Array Context:</B> (<TT>$name,

$aliases, $addrtype, $length, @addrs</TT>) or an empty

list.<BR>

<B>Definition:</B> Looks in the <TT>/etc/hosts</TT>

system file or checks a Domain Name Server for a server called

<TT>NAME</TT>.

<BLOCKQUOTE>

<PRE>

($name, $alias, $addrtype, $length, @addrs) = gethostbyname(&quot;lyNCh&quot;);

print(&quot;gethostbyname() [$alias].\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="gethostent">

gethostent ( )</A></H3>

<P>

<B>Category:</B> Host, UNIX<BR>

<B>Return Value: </B>in Scalar Context: Name of the next host

in <TT>/etc/hosts</TT>. or the undefined

value.<BR>

<B>Return Value in Array Context:</B> (<TT>$name</TT>,

<TT>$aliases</TT>, <TT>$addrtype</TT>,

<TT>$length</TT>, <TT>@addrs</TT>)

or an empty list.<BR>

<B>Definition:</B> Looks in the <TT>/etc/hosts</TT>

system file.

<BLOCKQUOTE>

<PRE>

($name, $alias, $addrtype, $length, @addrs) = gethostent();

print(&quot;gethostent() [$alias].\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getlogin">

getlogin ( )</A></H3>

<P>

<B>Category:</B> Process, UNIX<BR>

<B>Return Value:</B> SCALAR, the name of the current login.<BR>

<B>Definition:</B> Gets the current login name from the <TT>/etc/utmp</TT>

system file. Use <TT>getpwuid()</TT>for

more information on the login because the information stored in

<TT>/etc/utmp</TT> is limited.

<BLOCKQUOTE>

<PRE>

print (&quot;getlogin() &quot;, getlogin(), &quot;\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getnetbyaddrADDRESSADDRTYPE">

getnetbyaddr (ADDRESS, ADDR_TYPE)</A></H3>

<P>

<B>Category:</B> Network<BR>

<B>Return Value: </B>in Scalar Context: The network name that

has an address of <TT>ADDRESS</TT>

or undefined.<BR>

<B>Return Value in Array Context:</B> (<TT>$name</TT>,

<TT>$aliases</TT>, <TT>$addrtype</TT>,

<TT>$net</TT>) or an empty list.<BR>

<B>Definition:</B> Looks for the network information in the <TT>/etc/networks</TT>

system file.

<BLOCKQUOTE>

<PRE>

($addrtype) = (getnetent())[2];

($name, $alias, $addrtype, $net) = getnetbyaddr($net, $addrtype);

print(&quot;getnetbyaddr() Reads /etc/networks [$name]\n&quot;);

</PRE>

</BLOCKQUOTE>

<H3><A NAME="getnetbynameNAME">

getnetbyname (NAME)</A></H3>

<P>

<B>Category:</B> Network<BR>

<B>Return Value: </B>in Scalar Context: The network address of

<TT>NAME</TT> or undefined.<BR>

<B>Return Value in Array Context:</B> (<TT>$name</TT>,

<TT>$aliases</TT>, <TT>$addrtype</TT>,

<TT>$net</TT>) or an empty list.<BR>

<B>Definition:</B> Looks for the network information in the <TT>/etc/networks</TT>

system file.

<BLOCKQUOTE>

<PRE>

($name, $alias, $addrtype, $net) = getnetbyname(&quot;localnet&quot;);

⌨️ 快捷键说明

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