ch05_05.htm
来自「by Randal L. Schwartz and Tom Phoenix I」· HTM 代码 · 共 98 行
HTM
98 行
<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="ch05_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="ch06_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">5.5. Exercises</h2><p>See <a href="appa_04.htm#lperl3-APP-A-SECT-4">Section A.4, "Answers to Chapter 5 Exercises"</a> for answers to the followingexercises:</p><ol><li><p>[7] Write a program that will ask the user for a given name andreport the corresponding family name. Use the names of people youknow, or (if you spend so much time on the computer that youdon't know any actual people) use the following table:</p><a name="ch05-11-fm2xml" /><table border="1"><tr><th><p>Input</p></th><th><p>Output</p></th></tr><tr><td><p><tt class="literal">fred</tt></p></td><td><p><tt class="literal">flintstone</tt></p></td></tr><tr><td><p><tt class="literal">barney</tt></p></td><td><p><tt class="literal">rubble</tt></p></td></tr><tr><td><p><tt class="literal">wilma</tt></p></td><td><p><tt class="literal">flintstone</tt></p></td></tr></table><p></li><li><p>[15] Write a program that reads a series of words (with one word perline<a href="#FOOTNOTE-138">[138]</a>) until end-of-input, then prints asummary of how many times each word was seen. (Hint: remember thatwhen an undefined value is used as if it were a number, Perlautomatically converts it to <tt class="literal">0</tt>. It may help tolook back at the earlier exercise that kept a running total.) So, ifthe input words were <tt class="literal">fred</tt>,<tt class="literal">barney</tt>, <tt class="literal">fred</tt>,<tt class="literal">dino</tt>, <tt class="literal">wilma</tt>,<tt class="literal">fred</tt> (all on separate lines), the output shouldtell us that <tt class="literal">fred</tt> was seen <tt class="literal">3</tt>times. For extra credit, sort the summary words in ASCII order in theoutput.<a name="INDEX-418" /></p><blockquote class="footnote"> <a name="FOOTNOTE-138" /><p>[138]It has to be one word per line, because we stillhaven't shown you how to extract individual words from a lineof input.</p> </blockquote></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="ch05_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="ch06_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">5.4. Typical Use of a Hash</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">6. I/O Basics</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 + =
减小字号Ctrl + -
显示快捷键?