📄 ch24.htm
字号:
</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 ofan array in the same way that I think of a list because both arecomposed of many things. An array can be composed of numbers,strings, hashes, or even other arrays. A basic array assignmentlooks 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 & 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 elementsof 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 willautomatically 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 elementsof an array. Instead of specifying one index inside the squarebrackets, you can specify multiple indexes. You can either assignthe result of a slice of another array variable or assign newvalues 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 assignmentslook 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, "FuNCtion List."<H2><A NAME="ASCII"><FONT SIZE=5 COLOR=#FF0000>ASCII</FONT></A></H2><P>ASCII is a bit-mapped character set standard for interchangingtext eNCoded with 7-bits in an 8-bit byte. The ASCII standardwas created by the American National Standards Institute (ANSI).Each character maps directly to a number from 0 to 127. For example,the letter "A" is numbered 65 and "a" is numbered97. Generally, these numbers are displayed in hexadecimal format.For example, the letter "A" is 0x41 and "a"is 0x61. While ASCII is satisfactory for displaying the Englishlanguage, it is not considered adequate for non-English languagesbecause the 128 character choice is too limiting. For instaNCe,many European langugaes use accented characters which ASCII can'teasily 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 valueof <TT>4</TT> into the <TT>$foo</TT>variable. The left side of the statement must be a value-somethingthat ultimately will resolve to a memory location where the storagewill 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 indexesinstead of numbers; for example, <TT>$hash{'david'}</TT>or <TT>$hash{'Larry Wall'}</TT>. Notethat hashes use curly brackets around the index while arrays usesquare brackets.<H2><A NAME="Associativitylefttorightamprighttoleft"><FONT SIZE=5 COLOR=#FF0000>Associativity (left-to-right & right-to-left)</FONT></A></H2><P>Every Perl operator and fuNCtion has a tendeNCy to favor its leftor right when looking for operands. If the operator looks leftfirst-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 utilitythat 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 patternmatching head down the wrong path when looking for a pattern.SiNCe the current path-the set of characters being searched-iswrong, a new path needs to be found. Because this process is internalto Perl, you don't need to worry about the details. If you wantto know more, please see the documentation that came with yourPerl 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 outputin any way. By the way, this is my preferred mode of operation.Text mode-only available on some operating systems like Windows95 and Windows NT-will convert newline/carriage return characterpairs into a single newline. It will also interpret any byte thathas 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, Perllooks at the entire value. However, bitwise operators will seea value of 15 as a series of ones and zeros.<BR><A HREF="ch4.htm" >Chapter 4</A> "Operators," talks about bitwise operatorsand 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 curlybraces. Code blocks can be viewed as single-pass loops. Usingthe <TT>my()</TT> fuNCtion insidea 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 fuNCtioncan modify the parameters and the change can be seen by the callingfuNCtion 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 getat 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 tothe 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 decimaldigits. And [0-9a-f] defines the class of hexadecimal digits.<A HREF="ch10.htm" >Chapter 10</A>, "Regular Expressions," discusses characterclass 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 clonesof 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 multiplerequest 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 toemulate an object. An object can be anything you want it to be-apen, an ATM machine, a car, whatever. The class's variables (alsocalled properties) and fuNCtions (also called methods) are thecomputer's way of modeling the object. See <A HREF="ch14.htm" >Chapter 14</A>, "WhatAre Objects?" 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-orientedor rad, instead. Seriously though, C/S refers to the coNCept ofsplitting the workload for a given task. Typically, the work isbroken into user-interface tasks (like presenting informationand inputting information) and back-end tasks (querying databases,printing reports, and sorting information). A standard C/S Internetapplication would use a web browser for the client and a cgi-enabledWeb 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 Perlscript. They are called command-line options because you add themto 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 messagesabout questionable code. <A HREF="ch17.htm" >Chapter 17</A>, "Using Command-LineOptions," 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 anotherform-typically, a language that your CPU can directly understand.The secondary form is sometimes written to disk in the form ofan executable file; however, this is not always the case. In fact,Perl does not currently create executable files-although somepeople 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-timeerrors. 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 themtogether. The operation is frequently used with strings. In fact,Perl has its own coNCatenation operator-the period; for example,<TT>'one' . 'two'</TT> is equivalentto <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 nameto refer to a memory location that holds a value. The exceptionis that, with constants, that value can't change; with variables,it can. Normally, trying to change a constant would generate acompile-time error. Unfortunately, Perl does not have true constants,but you can emulate them by initializing a variable and then neverassigning a second value to it. Some programmers like to emulateconstants by using a fuNCtion to return a value. This works, butit 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 isusually done by creating an anonymous hash and storing the classesproperties inside the hash as entries. Most constructor fuNCtionsare 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 & Scalar)</FONT></A></H2><P>Sometimes you can control the type of value-either array or scalar-thatis returned from a fuNCtion. If you place parentheses around thefuNCtion call, the return value will be placed in an array (ofcourse, it might only be a one-element array). FuNCtion callsthat are themselves parameters to another fuNCtion are usuallyevaluated in an array context also. You can use the scalar() fuNCtionto create a scalar context. This is valuable when determiningthe size of an array. For example, scalar(@array) will returnthe 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, "FuNCtion List," 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 thedisplay. For example, displaying the value 7 usually causes abeep to sound. The control values map directly onto the Englishalphabet. Therefore, a value of 7 is Control G-also written asCtrl+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 representedby \r in strings. The carriage return can also be referred toas 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 collectionmight be another. Each book or stamp would typically have itsown record that contains information specific to that particular
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -