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

📄 ch06_06.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="ch06_05.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="ch07_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">6.6. Exercises</h2><p>See <a href="appa_05.htm#lperl3-APP-A-SECT-5">Section A.5, "Answers to Chapter 6 Exercises"</a> for answers to the followingexercises:</p><ol><li><p>[7] Write a program that acts like <i class="command">cat</i>, butreverses the order of the output lines. (Some systems have a utilitylike this named <i class="command">tac</i>.) If you run yours as<tt class="literal">./tac fred barney betty</tt>, the output should be allof file <i class="command">betty</i> from last line to first, then<i class="command">barney</i> and then <i class="command">fred</i>, also fromlast line to first. (Be sure to use the <tt class="literal">./</tt> in yourprogram's invocation if you call it <i class="command">tac</i>, sothat you don't get the system's utility instead!)</p></li><li><p>[8] Write a program that asks the user to enter a list of strings onseparate lines, printing each string in a right-justified20-character column. To be certain that the output is in the propercolumns, print a "ruler line" of digits as well. (This issimply a debugging aid.) Make sure that you're not using a19-character column by mistake! For example, entering<tt class="literal">hello</tt>, <tt class="literal">good-bye</tt> should giveoutput something like this:</p><blockquote><pre class="code">123456789012345678901234567890123456789012345678901234567890               hello            good-bye</pre></blockquote></li><li><p>[8] Modify the previous program to let the user choose the columnwidth, so that entering <tt class="literal">30</tt>,<tt class="literal">hello</tt>, <tt class="literal">good-bye</tt> (on separatelines) would put the strings at the 30th column. (Hint: see thesection <a href="ch02_06.htm#lperl3-CHP-2-SECT-6.1">Section 2.6.1, "Interpolation of Scalar Variables into Strings"</a> in <a href="ch02_01.htm">Chapter 2, "Scalar Data"</a> about controlling variable interpolation.) Forextra credit, make the ruler line longer when the selected width islarger.<a name="INDEX-490" /><a name="INDEX-491" /></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="ch06_05.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="ch07_01.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">6.5. Formatted Output with printf</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">7. Concepts of Regular Expressions</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 + -