📄 ch16_05.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 & 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="ch16_04.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="ch17_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">16.5. Exercises</h2><p>These exercises are all related; it may be helpful to see what thesecond and third should do before starting on the first. See <a href="appa_15.htm#lperl3-APP-A-SECT-15">Section A.15, "Answers to Chapter 16 Exercises"</a> for answers.</p><ol><li><p>[15] Make a program that will read through the<em class="filename">perlfunc.pod</em> file looking for identifier nameson <tt class="literal">=item</tt> lines (as in the similar exercise at theend of <a href="ch09_01.htm">Chapter 9, "Using Regular Expressions"</a>). The program should write adatabase showing the <em class="emphasis">first</em> line number on whicheach identifier appears. That is, if <tt class="literal">fred</tt> wasmentioned on lines 23, 29, and 54, the value stored under the key<tt class="literal">fred</tt> would be 23. (Hint: the special<tt class="literal">$.</tt> variable gives the line number of the line thatwas just read.)</p></li><li><p>[10] Make a program that will take a Perl function name on thecommand line, and report what <tt class="literal">=item</tt> line of the<em class="filename">perlfunc.pod</em> file first mentions that function.Your program should not have to read through a long file to get thisanswer. What should your program do if the function name isn'tfound?</p></li><li><p>[10] (Extra credit exercise.) Modify the program from the previousexercise so that when the function is found in the database, yourprogram will launch your favorite pager program to view the<em class="filename">perlfunc.pod</em> file at that line. (Hint: manyprograms that can be used for viewing text files work like<i class="command">less</i> does, with a command line like <tt class="literal">less+1234</tt> <em class="replaceable">filename</em> to start viewingthe file at line 1234. Your favorite text editor may also supportthis convention, which is also used by <i class="command">more</i>,<i class="command">pico</i>, <i class="command">vi</i>,<i class="command">emacs</i>, and <i class="command">view</i>.)<a name="INDEX-1089" /></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="ch16_04.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="ch17_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">16.4. Variable-length (Text) Databases</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">17. Some Advanced Perl Techniques</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 © 2002</a> O'Reilly & 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 + -