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

📄 ch23.htm

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

$

<LI>How is the <TT>next</TT> keyword

different from the <TT>redo</TT> keyword?

<BR>

<B>The </B><TT><B><FONT FACE="Courier">next</FONT></B></TT><B>

keyword is used to skip the rest of the statement block and continue

to the next iteration of the loop. The </B><TT><B><FONT FACE="Courier">redo</FONT></B></TT><B>

keyword is used to restart the statement block.</B>

<LI>Why is the comma operator useful in the initialization expression

of a <TT>for</TT> loop?<BR>

<B>Because you can use the comma operator to evaluate two expressions

at oNCe in the initialization and the iNCrement/decrement expressions.</B>

<LI>What is the <TT>shift()</TT> fuNCtion

used for?<BR>

<B>To value a local variable <I>and </I>remove the first element

of the parameter array from the array at the same time. If you

use </B><TT><B><FONT FACE="Courier">shift()</FONT></B></TT><B>

all by itself, the value of the first element is lost.</B>

</OL>

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

Chapter 8</FONT></A></H2>

<OL>

<LI>What is a refereNCe?<BR>

<B>A <I>refereNCe</I> is a scalar value that points to a memory

location that holds some type of data.</B>

<LI>How many types of refereNCes are there?<BR>

<B>Five.</B>

<LI>What does the <TT>ref()</TT> fuNCtion

return if passed a non-refereNCe as a <BR>

parameter?<BR>

<B>The </B><TT><B><FONT FACE="Courier">ref()</FONT></B></TT><B>

fuNCtion will return a string that contains the words &quot;Non-refereNCe.&quot;</B>

<LI>What notation is used to derefereNCe a refereNCe value?<BR>

<B>Curly braces.</B>

<LI>What is an anonymous array?<BR>

<B>Anonymous arrays are associative arrays that are not being

assigned directly to a variable.</B>

<LI>What is a nested data structure?<BR>

<B>A nested data structure is a data structure that contains another

data structure. Frequently, an object needs to contain another

object-just like a bag can contain groceries.</B>

<LI>What will the following line of code display?<BR>

<BR>

<TT>print(&quot;${\ref(\(1..5))}&quot;);

<BR>

This line of code displays:<BR>

ARRAY</TT>

</OL>

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

Chapter 9</FONT></A></H2>

<OL>

<LI>What is a file handle?<BR>

<B>File handles are variables used to manipulate files.</B>

<LI>What is binary mode?<BR>

<B>In binary mode on DOS systems, line endings are read as two

characters-the line feed and the carriage return. On both DOS

and UNIX systems, binary mode lets you read the end of file character

as regular characters with no special meaning.</B>

<LI>What is a fully qualified file name?<BR>

<B>The fully qualified name iNCludes the name of the disk, the

directory, and the file name.</B>

<LI>Are variables in the computer's memory considered persistent

storage?<BR>

<B>No</B>.

<LI>What is the &lt;&gt; operator used for?<BR>

<B>The &lt;&gt; characters, when used together, are called the

<I>diamond</I> operator. They tell Perl to read a line of input

from the file handle inside the operators.</B>

<LI>What is the default file handle for the <TT>printf()</TT>

fuNCtion?<BR>

<B>The default file handle is </B><TT><B><FONT FACE="Courier">STDOUT</FONT></B></TT><B>.</B>

<LI>What is the differeNCe between the following two open statements?

<BR>

<TT>open(FILE_ONE, &quot;&gt;FILE_ONE.DAT&quot;);

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;open(FILE_TWO, &quot;&gt;&gt;FILE_TWO.DAT&quot;);

<BR>

</TT>The &gt; character causes the file to be opened for

writing and causes any existing data in the file to be lost, whereas

the &gt;&gt; character sequeNCe will open the file for appending-preserving

the existing data. 

<LI>What value will the following expression return?<BR>

<TT>&nbsp;&nbsp;&nbsp;&nbsp;(stat(&quot;09lst01.pl&quot;))[7];

<BR>

</TT>This expression returns the size of the file.

<LI>What is globbing?<BR>

<B>Using wildcard characters to find filenames.</B>

<LI>What will the following statement display?<BR>

<BR>

<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%x&quot;,

16); <BR>

</TT>This statement displays:<BR>

<BR>

<TT>10</TT>

</OL>

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

Chapter 10</FONT></A></H2>

<OL>

<LI>Can you use variable interpolation with the translation operator?

<BR>

<B>No.</B>

<LI>What happens if the pattern is empty?<BR>

<B>The last pattern is used.</B>

<LI>What variable does the substitution operator use as its default?

<BR>

<B>All regular expression operators use $_ as the default search

space.</B>

<LI>Will the following line of code work?<BR>

m{.*];<BR>

<B>No. When using curly braces as alternative delimiters, the

end delimiter must be }.</B>

<LI>What is the /g option of the substitution operator used for?

<BR>

<B>The /g option forces all instaNCes of the pattern to be substituted,

not just the first.</B>

<LI>What does the \d meta-character sequeNCe mean?<BR>

<B>The \d sequeNCe is a symbolic character class that matches

digits.</B>

<LI>What is the meaning of the dollar sign in the following pattern?

<BR>

<TT>/AA[.&lt;]$]ER/<BR>

</TT><B>The dollar sign is the beginning of the special

variable $].</B>

<LI>What is a word boundary?<BR>

<B>A word boundary is that imaginary point between the end of

a word and the next character-which is usually a space character

or a puNCtuation mark.</B>

<LI>What will be displayed by the following program?<BR>

<TT>$_ = 'AB AB AC';<BR>

print m/c$/i;<BR>

</TT>This program displays:<BR>

<BR>

<TT>1</TT>

</OL>

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

Chapter 11</FONT></A></H2>

<OL>

<LI>What is the syntax of the format statement?<BR>

<TT>format FORMATNAME =<BR>

&nbsp;&nbsp;&nbsp;&nbsp;FIELD_LINE<BR>

&nbsp;&nbsp;&nbsp;&nbsp;VALUE_LINE<BR>

.</TT>

<LI>What is a footer?<BR>

<B>Footers are used at the bottom of each page and can only consist

of static text</B>.

<LI>What fuNCtion is used to invoke the format statement?<BR>

<B>The </B><TT><B><FONT FACE="Courier">write()</FONT></B></TT><B>

fuNCtion.</B>

<LI>How can you change a detail format line into a header format

line?<BR>

<B>By changing the field lines and value lines.</B>

<LI>What is the &gt; format character used for?<BR>

<B>This character indicates that the field should be right-justified.</B>

<LI>What is the <TT>$^L</TT> variable

used for?<BR>

<B>The </B><TT><B><FONT FACE="Courier">$^L</FONT></B></TT><B>

variable holds the string that Perl writes before every report

page except for the first.</B>

<LI>Can associative array variables be used in value lines?<BR>

<B>No.</B>

<LI>What will the following line of code do?<BR>

<TT>select((select(ANNUAL_RPT), $^ = &quot;REGIONAL_SALES&quot;)[0]);

<BR>

</TT><B>First </B><TT><B><FONT FACE="Courier">ANNUAL RPT</FONT></B></TT><B>

will be selected as the default file handle for the print and

write statements and then the $~ variable will be changed to the

new format name. By eNClosing the two statements inside parentheses

their return values will be used in an array context. SiNCe the

select fuNCtion returns the value of the previous default file

handle, after executing the second </B><TT><B><FONT FACE="Courier">select()</FONT></B></TT><B>

the default file handle will be restored to its previous value.</B>

</OL>

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

Chapter 12</FONT></A></H2>

<OL>

<LI>What is the <TT>$/</TT> variable

used for?<BR>

<B>This variable holds the input record separator.</B>

<LI>What file handle is used to avoid a second system call when

doing two or more file tests?<BR>

<B>The underscore.</B>

<LI>What will the following program display?<BR>

<TT>$_ = &quot;The big red shoe&quot;;<BR>

m/[rs].*\b/;<BR>

print(&quot;$`\n&quot;);<BR>

</TT>This program displays:<BR>

<TT>The Big</TT>

<LI>What variable holds the value of the last match string?<BR>

<TT>$&amp;</TT>

<LI>What will the following program display?<BR>

<TT>@array = (1..5);<BR>

$&quot; = &quot;+&quot;;<BR>

print(&quot;@array\n&quot;);<BR>

This program displays:<BR>

1+2+3+4+5</TT>

<LI>What does the following program display?<BR>

<BR>

<TT>@array = ('A'..'E');<BR>

<BR>

foreach (@array) {<BR>

&nbsp;&nbsp;&nbsp;&nbsp;print();<BR>

}<BR>

<BR>

$\ = &quot;\n&quot;;<BR>

foreach (@array) {<BR>

&nbsp;&nbsp;&nbsp;&nbsp;print();<BR>

}<BR>

</TT>This program displays:<BR>

<BR>

<TT>ABCDEA<BR>

B<BR>

C<BR>

D<BR>

E</TT>

</OL>

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

Chapter 13</FONT></A></H2>

<OL>

<LI>Why is it important to check for errors?<BR>

<B>There is only one way to check for errors in any programming

language. You need to test the return values of the fuNCtions

that you call. Most fuNCtions return zero or false when something

goes wrong. So when using a critical fuNCtion like </B><TT><B><FONT FACE="Courier">open()</FONT></B></TT><B>

or </B><TT><B><FONT FACE="Courier">sysread()</FONT></B></TT><B>,

checking the return value helps to ensure that your program will

work properly.</B>

<LI>How is the <TT>die()</TT> fuNCtion

different from the <TT>warn()</TT>

fuNCtion?<BR>

The <TT><B><FONT FACE="Courier">die()</FONT></B></TT> fuNCtion

is used to quit your script and display a message for the user

to read. The <TT><B><FONT FACE="Courier">warn()</FONT></B></TT>

fuNCtion has the same fuNCtionality that <TT><B><FONT FACE="Courier">die()</FONT></B></TT>

does except the script is not exited. This fuNCtion is better

suited for non-fatal messages like low memory or disk space conditions.

<LI>What is the meaning of the <TT>$!</TT>

special variable?<BR>

It helps to find out what happened after an error has occurred.

The <TT><B><FONT FACE="Courier">$!</FONT></B></TT> variable can

be used in either a numeric or a string context. In a numeric

context it holds the current value of <TT><B><FONT FACE="Courier">errno</FONT></B></TT>.

 If used in a string context, it will hold the error string associated

with <TT><B><FONT FACE="Courier">errno</FONT></B></TT>.

<LI>What does the <TT>eval()</TT>

fuNCtion do?<BR>

The <TT><B><FONT FACE="Courier">eval()</FONT></B></TT> fuNCtion

executes its arguments as semi-isolated Perl code. First the Perl

code in <TT><B><FONT FACE="Courier">$code</FONT></B></TT> is executed

and then, if an error arises, the Perl code in <TT><B><FONT FACE="Courier">$code</FONT></B></TT>

is displayed as text by the <TT><B><FONT FACE="Courier">die()</FONT></B></TT>

fuNCtion.

<LI>What is a signal?<BR>

<I>Signals</I> are messages sent to the process running your Perl

⌨️ 快捷键说明

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