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

📄 ch07_02.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
字号:
<html><head><title>Footers (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Footers"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch07_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch07_01.htm">Chapter 7: Formats</a></td><td align="right" valign="top" width="172"><a href="ch08_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">7.2. Footers</h2><a name="INDEX-1933"></a><a name="INDEX-1934"></a><a name="INDEX-1935"></a><a name="INDEX-1936"></a><p><a name="INDEX-1937"></a>While <tt class="literal">$^</tt> (<tt class="literal">$FORMAT_TOP_NAME</tt>) contains the name of the currentheader format, there is no corresponding mechanism to do the same thingautomatically for a footer.  Not knowing how big a format is going tobe until you evaluate it is one of the major problems.  It's on theTODO list.<a href="#FOOTNOTE-2">[2]</a></p><blockquote class="footnote"><a name="FOOTNOTE-2"></a><p>[2]That doesn't guarantee we'll ever do it, of course. Formats are somewhat pass&amp;#233; in this age of WWW, Unicode, XML, XSLT,and whatever the next few things after that are.</p></blockquote><p>Here's one strategy: if you have a fixed-size footer, you can getfooters by checking <tt class="literal">$-</tt> (<tt class="literal">$FORMAT_LINES_LEFT</tt>) before each <tt class="literal">write</tt>and then print the footer yourself if necessary.</p><p>Here's another strategy; open a pipe to yourself, using <tt class="literal">open(MESELF,"|-")</tt> (see the <tt class="literal">open</tt> entry in <a href="ch29_01.htm">Chapter 29, "Functions"</a>) and always<tt class="literal">write</tt> to <tt class="literal">MESELF</tt> instead of <tt class="literal">STDOUT</tt>. Have your child processpostprocess its <tt class="literal">STDIN</tt> to rearrange headers and footers however youlike.  Not very convenient, but doable.</p><h3 class="sect2">7.2.1. Accessing Formatting Internals</h3><a name="INDEX-1938"></a><p><a name="INDEX-1939"></a><a name="INDEX-1940"></a>For low-level access to the internal formatting mechanism, you may use the built-in<tt class="literal">formline</tt> operator and access <tt class="literal">$^A</tt> (the <tt class="literal">$ACCUMULATOR</tt> variable)directly.  (Formats essentially compile into a sequence of calls to<tt class="literal">formline</tt>.)  For example:<blockquote><pre class="programlisting">$str = formline &lt;&lt;'END', 1,2,3;@&lt;&lt;&lt;  @|||  @&gt;&gt;&gt;ENDprint "Wow, I just stored `$^A' in the accumulator!\n";</pre></blockquote>Or to create an <tt class="literal">swrite</tt> subroutine that is to <tt class="literal">write</tt> as<tt class="literal">sprintf</tt> is to <tt class="literal">printf</tt>, do this:<blockquote><pre class="programlisting">use Carp;sub swrite {    croak "usage: swrite PICTURE ARGS" unless @_;    my $format = shift;    $^A = "";    formline($format, @_);    return $^A;} $string = swrite(&lt;&lt;'END', 1, 2, 3);Check me out@&lt;&lt;&lt;  @|||  @&gt;&gt;&gt;ENDprint $string;</pre></blockquote><a name="INDEX-1941"></a><a name="INDEX-1942"></a><a name="INDEX-1943"></a></p><p>If you were using the <tt class="literal">FileHandle</tt> module, you could use <tt class="literal">formline</tt>as follows to wrap a block of text at column 72:<blockquote><pre class="programlisting">use FileHandle;STDOUT-&gt;formline("^" . ("&lt;" x 72) . "~~\n", $long_text);</pre></blockquote></p><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch07_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch08_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">7.1. Format Variables</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">8. References</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>

⌨️ 快捷键说明

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