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

📄 ch09_09.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>Exercises (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch09_08.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="ch10_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">9.9. Exercises</h2><p>See <a href="appa_08.htm#lperl3-APP-A-SECT-8">Section A.8, "Answers to Chapter 9 Exercises"</a> for answers to the followingexercises:</p><ol><li><p>[7] Make a pattern that will match three consecutive copies ofwhatever is currently contained in <tt class="literal">$what</tt>. That is,if <tt class="literal">$what</tt> is <tt class="literal">fred</tt>, your patternshould match <tt class="literal">fredfredfred</tt>. If<tt class="literal">$what</tt> is <tt class="literal">fred|barney</tt>, yourpattern should match <tt class="literal">fredfredbarney</tt> or<tt class="literal">barneyfredfred</tt> or<tt class="literal">barneybarneybarney</tt> or many other variations.(Hint: You should set <tt class="literal">$what</tt> at the top of thepattern test program with a statement like <tt class="literal">my $what ='fred|barney';</tt>.)</p></li><li><p>[15] Write a program that looks through the<tt class="literal">perlfunc.pod</tt> file for lines that start with<tt class="literal">=item</tt> and some whitespace, followed by a Perlidentifier name (made of letters, digits, and underscores, but neverstarting with a digit), like the lines below. (There may be more texton the line after the identifier name; just ignore it.) You canlocate the <tt class="literal">perlfunc.pod</tt> file on your system withthe command <tt class="literal">perldoc -l perlfunc</tt>, or ask your localexpert. (Hint: You'll need the diamond operator to open thisfile. How will it get the filename?) Have the program print eachidentifier name as it finds it; there will be hundreds of them, andmany will appear more than once in the file.</p><p>As an example, the following lines of input resemble whatyou'll find in <tt class="literal">perlfunc.pod</tt>. For the firstline, the program should print <tt class="literal">wilma</tt>. For thesecond, it should print <tt class="literal">fred</tt> (ignoring the word<tt class="literal">flintstone</tt>, since we're interested only inthe identifier name):</p><blockquote><pre class="code">=item wilma =item fred flintstone</pre></blockquote></li><li><p>[10] Modify the previous program to list only the identifier namesthat appear more than twice on those <tt class="literal">=item</tt> lines,and tell how many times each one appeared. (That is, we want to knowwhich identifier names appear on at least three separate<tt class="literal">=item</tt> lines in the file.) There should be a coupleof dozen, depending upon your version of Perl.<a name="INDEX-636" /></p></li></ol><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch09_08.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="ch10_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">9.8. The join Function</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">10. More Control Structures</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

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