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

📄 ch24.htm

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

<H2><A NAME="Argument"><FONT SIZE=5 COLOR=#FF0000>

Argument</FONT></A></H2>

<BLOCKQUOTE>

See <I>Parameter</I>.

</BLOCKQUOTE>

<H2><A NAME="Array"><FONT SIZE=5 COLOR=#FF0000>

Array</FONT></A></H2>

<P>

An array is a collection of values stored as a unit. I think of

an array in the same way that I think of a list because both are

composed of many things. An array can be composed of numbers,

strings, hashes, or even other arrays. A basic array assignment

looks like this: <TT>@array = (1, 2, 'Three',

4);</TT>.

<H2><A NAME="ArrayContext"><FONT SIZE=5 COLOR=#FF0000>

Array Context</FONT></A></H2>

<P>

See <I>Context </I>(<I>Array &amp; Scalar</I>).

<H2><A NAME="ArrayRange"><FONT SIZE=5 COLOR=#FF0000>

Array Range</FONT></A></H2>

<P>

A range is a shorthand method for generating consecutive elements

of an array. For example, <TT>@array = (1..6)</TT>

is equivalent to <TT>@array = (1, 2, 3, 4,

5, 6)</TT>. You can also create letter ranges-Perl will

automatically generate the missing letters. For example, <TT>@array

= ('AA'..'AD')</TT> is equivalent to <TT>@array

= ('AA', 'AB', 'AC', 'AD')</TT>.

<H2><A NAME="ArraySlice"><FONT SIZE=5 COLOR=#FF0000>

Array Slice</FONT></A></H2>

<P>

A slice is a shorthand method for specifying specific elements

of an array. Instead of specifying one index inside the square

brackets, you can specify multiple indexes. You can either assign

the result of a slice of another array variable or assign new

values to the specified elements. For example, <TT>@array[0,

6]</TT> refers to the 1<FONT SIZE=1>st</FONT> and 7<FONT SIZE=1>th</FONT>

elements in the array. <TT>@array[0..4]</TT>

refers to the elements from 0 to 4-five in all. Slice assignments

look like this: <TT>@array[0..2] = @foo;</TT>

or <TT>@array[0..2] = ('one', $two, 'three');</TT>.

<H2><A NAME="ArraySplice"><FONT SIZE=5 COLOR=#FF0000>

Array Splice</FONT></A></H2>

<P>

A splice is a way to modify an array variable to add, delete,

or replace elements. See the description of the <TT>splice()</TT>

fuNCtion in Appendix C, &quot;FuNCtion List.&quot;

<H2><A NAME="ASCII"><FONT SIZE=5 COLOR=#FF0000>

ASCII</FONT></A></H2>

<P>

ASCII is a bit-mapped character set standard for interchanging

text eNCoded with 7-bits in an 8-bit byte. The ASCII standard

was created by the American National Standards Institute (ANSI).

Each character maps directly to a number from 0 to 127. For example,

the letter &quot;A&quot; is numbered 65 and &quot;a&quot; is numbered

97. Generally, these numbers are displayed in hexadecimal format.

For example, the letter &quot;A&quot; is 0x41 and &quot;a&quot;

is 0x61. While ASCII is satisfactory for displaying the English

language, it is not considered adequate for non-English languages

because the 128 character choice is too limiting. For instaNCe,

many European langugaes use accented characters which ASCII can't

easily handle.

<BLOCKQUOTE>

See also <I>ANSI</I>.

</BLOCKQUOTE>

<H2><A NAME="Assignment"><FONT SIZE=5 COLOR=#FF0000>

Assignment</FONT></A></H2>

<P>

An assignment statement stores a value into a variable. For example,

<TT>$foo = 4</TT> stores the value

of <TT>4</TT> into the <TT>$foo</TT>

variable. The left side of the statement must be a value-something

that ultimately will resolve to a memory location where the storage

will take place.

<H2><A NAME="AssociativeArray"><FONT SIZE=5 COLOR=#FF0000>

Associative Array</FONT></A></H2>

<P>

An associative array-also called a hash-uses strings as indexes

instead of numbers; for example, <TT>$hash{'david'}</TT>

or <TT>$hash{'Larry Wall'}</TT>. Note

that hashes use curly brackets around the index while arrays use

square brackets.

<H2><A NAME="Associativitylefttorightamprighttoleft"><FONT SIZE=5 COLOR=#FF0000>

Associativity (left-to-right &amp; right-to-left)</FONT></A></H2>

<P>

Every Perl operator and fuNCtion has a tendeNCy to favor its left

or right when looking for operands. If the operator looks left

first-like the string coNCatenation operator-then it has left-associativity.

If it looks right first-like the minus sign-then it has right-associativity.

<H2><A NAME="awk"><FONT SIZE=5 COLOR=#FF0000>

awk</FONT></A></H2>

<P>

<TT>awk</TT> is a UNIX-based utility

that scans input lines for a specific pattern. Perl has most,

if not all, of the abilities of <TT>awk</TT>.

<BLOCKQUOTE>

See also <I>Pattern</I>.

</BLOCKQUOTE>

<H2><A NAME="Backtracking"><FONT SIZE=5 COLOR=#FF0000>

Backtracking</FONT></A></H2>

<P>

Backtracking happens when the internal routines that perform pattern

matching head down the wrong path when looking for a pattern.

SiNCe the current path-the set of characters being searched-is

wrong, a new path needs to be found. Because this process is internal

to Perl, you don't need to worry about the details. If you want

to know more, please see the documentation that came with your

Perl distribution.

<BLOCKQUOTE>

See also <I>Regular Expression</I>.

</BLOCKQUOTE>

<H2><A NAME="BinaryMode"><FONT SIZE=5 COLOR=#FF0000>

Binary Mode</FONT></A></H2>

<P>

When using files, you can use either binary mode or text mode.

Binary mode means that Perl will not change your input or output

in any way. By the way, this is my preferred mode of operation.

Text mode-only available on some operating systems like Windows

95 and Windows NT-will convert newline/carriage return character

pairs into a single newline. It will also interpret any byte that

has a value of 26 as the end-of-file marker.

<H2><A NAME="BitwiseOperations"><FONT SIZE=5 COLOR=#FF0000>

Bitwise Operations</FONT></A></H2>

<P>

Bitwise operators view values at the bit level. Usually, Perl

looks at the entire value. However, bitwise operators will see

a value of 15 as a series of ones and zeros.<BR>

<A HREF="ch4.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch4.htm" >Chapter 4</A> &quot;Operators,&quot; talks about bitwise operators

and how they can be used.

<H2><A NAME="Block"><FONT SIZE=5 COLOR=#FF0000>

Block</FONT></A></H2>

<P>

A block of code is a series of statements surrounded by curly

braces. Code blocks can be viewed as single-pass loops. Using

the <TT>my()</TT> fuNCtion inside

a code block will create a variable local to that block.

<BLOCKQUOTE>

See also <I>Scope</I>.

</BLOCKQUOTE>

<H2><A NAME="CallbyRefereNCe"><FONT SIZE=5 COLOR=#FF0000>

Call by RefereNCe</FONT></A></H2>

<P>

Many fuNCtions need information before they can do their work.

This information is given to fuNCtions in the form of parameters.

For example, in the fuNCtion call <TT>foo('one',

'two')</TT>, the strings <TT>'one'</TT>

and <TT>'two'</TT> are parameters.

When parameters are passed to the fuNCtion by refereNCe, the fuNCtion

can modify the parameters and the change can be seen by the calling

fuNCtion or program. For example, <TT>foo(\$result)</TT>

passes a refereNCe to the <TT>$result</TT>

variable into the <TT>foo()</TT> fuNCtion.

Inside the fuNCtion, the refereNCe can be derefereNCed to get

at and modify the value of <TT>$result</TT>.

<BLOCKQUOTE>

See also <I>Call by Value</I>.

</BLOCKQUOTE>

<H2><A NAME="CallbyValue"><FONT SIZE=5 COLOR=#FF0000>

Call by Value</FONT></A></H2>

<P>

Many fuNCtions need information before they can do their work.

This information is given to fuNCtions in the form of parameters.

For example, in the fuNCtion call <TT>foo('one',

'two')</TT>, the strings <TT>'one'</TT>

and <TT>'two'</TT> are parameters.

When parameters are passed to the fuNCtion by value, changes to

the value inside the fuNCtion are not seen outside the fuNCtion.

<BLOCKQUOTE>

See also <I>Call by RefereNCe</I>.

</BLOCKQUOTE>

<H2><A NAME="CharacterClasses"><FONT SIZE=5 COLOR=#FF0000>

Character Classes</FONT></A></H2>

<P>

A character class-used in pattern matching-defines a type of character.

The character class [0123456789] defines the class of decimal

digits. And [0-9a-f] defines the class of hexadecimal digits.

<A HREF="ch10.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch10.htm" >Chapter 10</A>, &quot;Regular Expressions,&quot; discusses character

class in detail.

<BLOCKQUOTE>

See <I>Regular Expression</I>.

</BLOCKQUOTE>

<H2><A NAME="ChildProcess"><FONT SIZE=5 COLOR=#FF0000>

Child Process</FONT></A></H2>

<P>

Some operating systems-such as UNIX-let your program create clones

of itself using the <TT>fork()</TT>

fuNCtion. These clones are called child processes or subprocesses.

Child processes are frequently used by server processes. For example,

you might fork a process (create a child process) to handle multiple

request on a single socket.

<H2><A NAME="Class"><FONT SIZE=5 COLOR=#FF0000>

Class</FONT></A></H2>

<P>

A class is a combination of variables and fuNCtions designed to

emulate an object. An object can be anything you want it to be-a

pen, an ATM machine, a car, whatever. The class's variables (also

called properties) and fuNCtions (also called methods) are the

computer's way of modeling the object. See <A HREF="ch14.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch14.htm" >Chapter 14</A>, &quot;What

Are Objects?&quot; for more information.

<BLOCKQUOTE>

See also <I>ENCapsulation</I>, <I>InheritaNCe</I>, and <I>Polymorphism</I>.

</BLOCKQUOTE>

<H2><A NAME="ClientServer"><FONT SIZE=5 COLOR=#FF0000>

Client/Server</FONT></A></H2>

<P>

Client/Server is a buzzword that is past its prime. Use object-oriented

or rad, instead. Seriously though, C/S refers to the coNCept of

splitting the workload for a given task. Typically, the work is

broken into user-interface tasks (like presenting information

and inputting information) and back-end tasks (querying databases,

printing reports, and sorting information). A standard C/S Internet

application would use a web browser for the client and a cgi-enabled

Web server as the server.

<H2><A NAME="CommandLineOptions"><FONT SIZE=5 COLOR=#FF0000>

Command-Line Options</FONT></A></H2>

<P>

Perl has several options you can control when invoking your Perl

script. They are called command-line options because you add them

to the command that invokes Perl. For example, in the command

<TT>perl -w test.pl</TT>, the <TT>-w</TT>

is a command-line option which causes Perl to display messages

about questionable code. <A HREF="ch17.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch17.htm" >Chapter 17</A>, &quot;Using Command-Line

Options,&quot; has a description of all of the available options.

<H2><A NAME="Compiler"><FONT SIZE=5 COLOR=#FF0000>

Compiler</FONT></A></H2>

<P>

A compiler reads your program code and converts it into another

form-typically, a language that your CPU can directly understand.

The secondary form is sometimes written to disk in the form of

an executable file; however, this is not always the case. In fact,

Perl does not currently create executable files-although some

people are researching this topic.

<BLOCKQUOTE>

See also <I>Interpreter</I>.

</BLOCKQUOTE>

<H2><A NAME="CompileTimeError"><FONT SIZE=5 COLOR=#FF0000>

Compile-Time Error</FONT></A></H2>

<P>

The errors caught during the compilation phase are called compile-time

errors. When the compiler converts a program to an internal format,

it checks for syntax errors and, if the <TT>-w</TT>

option is turned on, questionable coding practices.

<H2><A NAME="CoNCatenation"><FONT SIZE=5 COLOR=#FF0000>

CoNCatenation</FONT></A></H2>

<P>

CoNCatenation consists of taking two things and sticking them

together. The operation is frequently used with strings. In fact,

Perl has its own coNCatenation operator-the period; for example,

<TT>'one' . 'two'</TT> is equivalent

to <TT>'onetwo'</TT>.

<H2><A NAME="Constant"><FONT SIZE=5 COLOR=#FF0000>

Constant</FONT></A></H2>

<P>

In programming circles, a constant is a value that doesn't change.

Constants are very similar to variables because both use a name

to refer to a memory location that holds a value. The exception

is that, with constants, that value can't change; with variables,

it can. Normally, trying to change a constant would generate a

compile-time error. Unfortunately, Perl does not have true constants,

but you can emulate them by initializing a variable and then never

assigning a second value to it. Some programmers like to emulate

constants by using a fuNCtion to return a value. This works, but

it is very, very slow.

<H2><A NAME="Constructor"><FONT SIZE=5 COLOR=#FF0000>

Constructor</FONT></A></H2>

<P>

Classes use constructor fuNCtions to create an object. This is

usually done by creating an anonymous hash and storing the classes

properties inside the hash as entries. Most constructor fuNCtions

are named <TT>new()</TT>.

<BLOCKQUOTE>

See also <I>Classes</I> and <I>Deconstructor</I>.

</BLOCKQUOTE>

<H2><A NAME="ContextArrayampScalar"><FONT SIZE=5 COLOR=#FF0000>

Context (Array &amp; Scalar)</FONT></A></H2>

<P>

Sometimes you can control the type of value-either array or scalar-that

is returned from a fuNCtion. If you place parentheses around the

fuNCtion call, the return value will be placed in an array (of

course, it might only be a one-element array). FuNCtion calls

that are themselves parameters to another fuNCtion are usually

evaluated in an array context also. You can use the scalar() fuNCtion

to create a scalar context. This is valuable when determining

the size of an array. For example, scalar(@array) will return

the number of elements in @array.<BR>

<p>

<CENTER>

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

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

FuNCtions can use the <TT>wantarray()</TT> fuNCtion to determine their own calling context. Appendix C, &quot;FuNCtion List,&quot; has an example that uses the <TT>wantarray()</TT> fuNCtion.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H2><A NAME="ControlCharacters"><FONT SIZE=5 COLOR=#FF0000>

Control Characters</FONT></A></H2>

<P>

Control characters are characters that control devices-like the

display. For example, displaying the value 7 usually causes a

beep to sound. The control values map directly onto the English

alphabet. Therefore, a value of 7 is Control G-also written as

Ctrl+G or ^G.

<H2><A NAME="CR"><FONT SIZE=5 COLOR=#FF0000>

CR</FONT></A></H2>

<P>

CR is the abbreviation for carriage return. A CR is represented

by \r in strings. The carriage return can also be referred to

as Ctrl+J, ^J, 0x0a, or as an ASCII value of 10.

<BLOCKQUOTE>

See also <I>ASCII </I>and <I>Control Characters</I>.

</BLOCKQUOTE>

<H2><A NAME="Database"><FONT SIZE=5 COLOR=#FF0000>

Database</FONT></A></H2>

<P>

A database is a grouping of related information. For example,

your book collection might be one database and your stamp collection

might be another. Each book or stamp would typically have its

own record that contains information specific to that particular

⌨️ 快捷键说明

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