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

📄 ch23.htm

📁 this is a book on pearl , simple example with explanation is given here. it could be beneficial for
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML><HEAD><TITLE>Appendix A -- Answers to Review Questions</TITLE><META></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910"><H1><FONT SIZE=6 COLOR=#FF0000>Appendix&nbsp;A</FONT></H1><H1><FONT SIZE=6 COLOR=#FF0000>Answers to Review Questions</FONT></H1><HR><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 1</FONT></A></H2><OL><LI>What is the address of Perl's home page?<BR><B>http://www.perl.com/</B><LI>Who was the creator of Perl?<BR><B>Larry Wall</B><LI>How much does Perl cost?<BR><B>Free</B><LI>Why are comments important to Programming?<BR><B>Comments will enable you to figure out the intent behind themechanics of your program.</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 2</FONT></A></H2><OL><LI>What are the four types of data that can be used in literals?<BR><B>Literals can be Numeric, Strings, Arrays, or Associative Arrays.</B><LI>What are numeric literals?<BR><B>They represent a number that your program will need to workwith.</B><LI>How many types of string literals are there?<BR><B>Three-Single-quoted, double-quoted, and back-quoted. </B><LI>What is the major differeNCe between single- and double-quotedstrings?<BR><B>Double-quoted strings allow the use of variables.</B><LI>What are three escape sequeNCes and what do they mean?<BR><B>Any value in this table would be correct:</B></OL><P><P><CENTER><B>Table A.1&nbsp;&nbsp;Escape SequeNCes</B></CENTER><p><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR><TD WIDTH=145><CENTER><I>Escape SequeNCes</I></CENTER></TD><TD WIDTH=386><I>Description or Character</I></TD></TR><TR><TD WIDTH=145><CENTER>\a</CENTER></TD><TD WIDTH=386>Alarm\bell</TD></TR><TR><TD WIDTH=145><CENTER>\b</CENTER></TD><TD WIDTH=386>Backspace</TD></TR><TR><TD WIDTH=145><CENTER>\e</CENTER></TD><TD WIDTH=386>Escape</TD></TR><TR><TD WIDTH=145><CENTER>\f</CENTER></TD><TD WIDTH=386>Form Feed</TD></TR><TR><TD WIDTH=145><CENTER>\n</CENTER></TD><TD WIDTH=386>Newline</TD></TR><TR><TD WIDTH=145><CENTER>\r</CENTER></TD><TD WIDTH=386>Carriage Return</TD></TR><TR><TD WIDTH=145><CENTER>\t</CENTER></TD><TD WIDTH=386>Tab</TD></TR><TR><TD WIDTH=145><CENTER>\v</CENTER></TD><TD WIDTH=386>Vertical Tab</TD></TR><TR><TD WIDTH=145><CENTER>\$</CENTER></TD><TD WIDTH=386>Dollar Sign</TD></TR><TR><TD WIDTH=145><CENTER>\@</CENTER></TD><TD WIDTH=386>Ampersand</TD></TR><TR><TD WIDTH=145><CENTER>\%</CENTER></TD><TD WIDTH=386>Percent Sign</TD></TR><TR><TD WIDTH=145><CENTER>\0nnn</CENTER></TD><TD WIDTH=386>Any octal byte</TD></TR><TR><TD WIDTH=145><CENTER>\xnn</CENTER></TD><TD WIDTH=386>Any hexadecimal byte</TD></TR><TR><TD WIDTH=145><CENTER>\cn</CENTER></TD><TD WIDTH=386>Any Control character</TD></TR><TR><TD WIDTH=145><CENTER>\l</CENTER></TD><TD WIDTH=386>Change the next character to lowercase</TD></TR><TR><TD WIDTH=145><CENTER>\u</CENTER></TD><TD WIDTH=386>Change the next character to uppercase</TD></TR><TR><TD WIDTH=145><CENTER>\L</CENTER></TD><TD WIDTH=386>Change the following characters to lowercase until an \E sequeNCe is eNCountered</TD></TR><TR><TD WIDTH=145><CENTER>\U</CENTER></TD><TD WIDTH=386>Change the following characters to uppercase until an \E sequeNCe is eNCountered</TD></TR><TR><TD WIDTH=145><CENTER>\E</CENTER></TD><TD WIDTH=386>Terminate the \L or \U sequeNCe</TD></TR><TR><TD WIDTH=145><CENTER>\\</CENTER></TD><TD WIDTH=386>Backslash</TD></TR></TABLE></CENTER><P><OL><LI>What would the following one-line program display?<BR>print 'dir c:\*.log';<BR><B>This would display all files with the extension of LOG on aDOS system.</B><LI>What is scientific notation?<BR><B>A means of displaying very large or very small numbers in abase-10 notation.</B><LI>How can you represent the number 64 in hexadecimal insidea double-quoted string?<BR><B>&quot;0x40&quot;</B><LI>What is the easiest way to represent an array that iNCludesthe numbers 56 to 87?<BR><B>(56..87)</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 3</FONT></A></H2><OL><LI>What are the three basic data types that Perl uses?<BR><B>Scalar, array, and associative array.</B><LI>How can you determine the number of elements in an array?<BR><B>You can assign the array variable to a scalar variable.</B><LI>What is a namespace?<BR><B>A namespace is a way to segregate one type of name from another.The scalar variables use one namespace and array variables useanother.</B><LI>What is the special variable $[ used for?<BR><B>The $[ variable can tell you the base array subscript.</B><LI>What is the special variable $&quot; used for?<BR><B>The $&quot; variable determines what character or string isused to separate array elements when they are printed using adouble-quoted string and variable interpolation.</B><LI>What is the value of a variable when it is first used?<BR><B>In a numeric context, zero. In a string context, an empty string.</B><LI>What is an associative array?<BR><B>An associative array is an array that can use non-numbers asarray subscripts. A scalar key is used as the subscript to retrievean associated value.</B><LI>How can you access associative array elements?<BR><B>You use curly braces around the subscript and a $ to beginthe variable name.</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 4</FONT></A></H2><OL><LI>What are three arithmetic operators?<BR><B>+ Addition<BR><B>- Subtraction<BR><B>* Multiplication<BR><B>/ Division</B></B></B></B><LI>What does the x operator do?<BR><B>Returns the string to the left of x and repeats it the numberof times listed to the right of the x.</B><LI>What does it mean to pre-decrement a variable?<BR><B>To reduce the value of the variable by one before it is used.</B><LI>What is the value of 1 ^ 1?<BR><B>1</B><LI>What is the value of 1 &lt;&lt; 3?<BR><B>8</B><LI>What is the ternary operator used for?<BR><B>The <I>ternary</I> operator is actually a sequeNCe of operatorsdesigned to choose between two options.</B><LI>Can the x operator be used with arrays?<BR><B>Yes.</B><LI>What is the precedeNCe level of the range operator?<BR><B>4</B><LI>What is the value of 2 <FONT FACE="Symbol">&#165;</FONT> 5+ 10?<BR><B>20</B><LI>What is the value of 65 &gt;&gt; 1?<BR><B>32</B><LI>What is the spaceship operator used for?<BR><B>Compares two values and returns a -1 for less than and a +1for greater than.</B><LI>If an array was defined with (&quot;fy&quot;..&quot;gb&quot;),how many elements would it have?<BR><B>4</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 5</FONT></A></H2><OL><LI>What is a parameter?<BR><B>Values that get passed to a fuNCtion.</B><LI>What two fuNCtions are used to create variables with localscope?<BR><TT><B><FONT FACE="Courier">local()</FONT></B></TT><B> and </B><TT><B><FONT FACE="Courier">my()</FONT></B></TT><LI>What does parameter passing by refereNCe mean?<BR><B>When parameters are called by refereNCe, changing their valuein the fuNCtion also changes their value in the main program.</B><LI>What is the <TT>@_</TT> arrayused for?<BR><B>To store arguments used by Perl.</B><LI>Do Perl variables have global or local scope by default?<BR><B>Global.</B><LI>Why is it hard to pass two arrays to a fuNCtion?<BR><B>Because passing an array will change the values in the mainprogram as well as the fuNCtion.</B><LI>What is the differeNCe between variables created with <TT>local()</TT>and variables created with <TT>my()</TT>?<BR><B>The </B><TT><B><FONT FACE="Courier">my()</FONT></B></TT><B>fuNCtion creates variables that only the current procedure orcode block can see. The </B><TT><B><FONT FACE="Courier">local()</FONT></B></TT><B>fuNCtion, however, creates variables that procedures called fromthe current procedure can see.</B><LI>What does the <TT>map()</TT> fuNCtiondo?<BR><B>This fuNCtion will evaluate an expression for every elementof a given array. The special variable </B><TT><B><FONT FACE="Courier">$_</FONT></B></TT><B>is assigned each element of the specified array before the expressionis evaluated.</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 6</FONT></A></H2><OL><LI>What is an expression?<BR><B>It is a sequeNCe of literals, variables, or fuNCtions connectedby one or more operators that evaluate to a single value-scalaror array.</B><LI>What is a statement?<BR><B>Statements are a complete unit of instruction for the computerto process.</B><LI>What are the four statement modifiers?<BR><B>if, unless, until, and while</B><LI>What are two uses for statement blocks?<BR><B>As a visual device to mark sections of code and a way to createlocal variables and when you temporarily need to send debuggingoutput to a file.</B><LI>What can non-action statements be used for?<BR><B>These statements evaluate a value, but perform no actions.</B><LI>How is the if modifier different from the unless modifier?<BR><B>The <I>if</I> modifier will tell Perl that the expression shouldonly be evaluated if a given condition is true.  The <I>unless</I>modifier will evaluate an expression unless a condition is true.</B></OL><H2><A NAME="Chapter"><FONT SIZE=5 COLOR=#FF0000>Chapter 7</FONT></A></H2><OL><LI>What are the four loop keywords?<BR><B>While, until, for, and foreach.</B><LI>What are the four jump keywords?<BR><B>Last, next, redo, and goto.</B><LI>Which form of the until statement is used when the statementblock needs to be executed at least oNCe?<BR><B>The do..until loop.</B><LI>What will be displayed when this program executes?<BR><BR><TT>$firstVar = 5;<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if ($firstVar &gt; 10) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;$firstVar++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;redo;<BR>}<BR>print(&quot;$firstVar\n&quot;);<BR>This program will display:<BR>11</TT><LI>What is the default name of the local variable in the <TT>foreach</TT>loop?<BR>

⌨️ 快捷键说明

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