亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch24_04.htm

?? 編程珍珠,里面很多好用的代碼,大家可以參考學習呵呵,
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<html><head><title>Fluent Perl (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="Fluent Perl"><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="ch24_03.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch24_01.htm">Chapter 24: Common Practices</a></td><td align="right" valign="top" width="172"><a href="ch24_05.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">24.4. Fluent Perl</h2><p><a name="INDEX-4278"></a><a name="INDEX-4279"></a><a name="INDEX-4280"></a>We've touched on a few idioms in the preceding sections (not to mentionthe preceding chapters), but there are many other idioms you'llcommonly see if you read programs by accomplished Perl programmers.When we speak of idiomatic Perl in this context, we don't just mean aset of arbitrary Perl expressions with fossilized meanings.Rather, we mean Perl code that shows an understanding of the flow ofthe language, what you can get away with when, and what that buysyou.  And when to buy it.</p><p>We can't hope to list all the idioms you might see--that would take abook as big as this one.  Maybe two.  (See the <em class="emphasis">PerlCookbook</em>, for instance.)  But here are some of theimportant idioms, where "important" might be defined as "that whichinduces hissy fits in people who think they already know just howcomputer languages ought to work".</p><ul><li><p>Use <tt class="literal">=&gt;</tt> in place of a comma anywhere you think it improves readability:<blockquote><pre class="programlisting">return bless $mess =&gt; $class;</pre></blockquote>This reads, "Bless this mess into the specified class."  Just be carefulnot to use it after a word that you don't want autoquoted:<blockquote><pre class="programlisting">sub foo () { "FOO" }sub bar () { "BAR" }print foo =&gt; bar;   # prints fooBAR, not FOOBAR;</pre></blockquote>Another good place to use <tt class="literal">=&gt;</tt> is near a literalcomma that might get confused visually:<blockquote><pre class="programlisting">join(", " =&gt; @array);</pre></blockquote>Perl provides you with more than one way to do things so that you canexercise your ability to be creative.  Exercise it!</p></li><li><p>Use the singular pronoun to increase readability:<blockquote><pre class="programlisting">for (@lines) {    $_ .= "\n";}</pre></blockquote>The <tt class="literal">$_</tt> variable is Perl's version of a pronoun, and it essentiallymeans "it".  So the code above means "for each line, append a newline to<em class="emphasis">it</em>."  Nowadays you might even spell that:<blockquote><pre class="programlisting">$_ .= "\n" for @lines;</pre></blockquote>The <tt class="literal">$_</tt> pronoun is so important to Perl that its useis mandatory in <tt class="literal">grep</tt> and <tt class="literal">map</tt>.Here is one way to set up a cache of common results of an expensivefunction:<blockquote><pre class="programlisting">%cache = map { $_ =&gt; expensive($_) } @common_args;$xval = $cache{$x} || expensive($x);</pre></blockquote></p></li><li><p>Omit the pronoun to increase readability even further.<a href="#FOOTNOTE-1">[1]</a></p><blockquote class="footnote"><a name="FOOTNOTE-1"></a><p>[1]In this section, multiple bullet items in a row all refer to the subsequent example, since some of our examples illustrate more than one idiom.</p></blockquote></li><li><p>Use loop controls with statement modifiers.<blockquote><pre class="programlisting">while (&lt;&gt;) {    next if /^=for\s+(index|later)/;    $chars += length;    $words += split;    $lines += y/\n//;}</pre></blockquote>This is a fragment of code we used to do page counts for this book.  Whenyou're going to be doing a lot of work with the same variable, it'soften more readable to leave out the pronouns entirely, contrary tocommon belief.</p><p>The fragment also demonstrates the idiomatic use of <tt class="literal">next</tt>with a statement modifier to short-circuit a loop.</p><p>The <tt class="literal">$_</tt> variable is always the loop control variablein <tt class="literal">grep</tt> and <tt class="literal">map</tt>, but theprogram's reference to it is often implicit:<blockquote><pre class="programlisting">@haslen = grep { length } @random;</pre></blockquote>Here we take a list of random scalars and only pick the ones that havea length greater than <tt class="literal">0</tt>.</p></li><li><p>Use <tt class="literal">for</tt> to set the antecedent for a pronoun:<blockquote><pre class="programlisting">for ($episode) {    s/fred/barney/g;    s/wilma/betty/g;    s/pebbles/bambam/g;}</pre></blockquote>So what if there's only one element in the loop?  It's a convenientway to set up "it", that is, <tt class="literal">$_</tt>.  Linguistically, this is knownas topicalization.  It's not cheating, it's communicating.</p></li><li><p>Implicitly reference the plural pronoun, <tt class="literal">@_</tt>.</p></li><li><p>Use control flow operators to set defaults:<blockquote><pre class="programlisting">sub bark {    my Dog $spot = shift;    my $quality  = shift || "yapping";    my $quantity = shift || "nonstop";     ...}</pre></blockquote>Here we're implicitly using the other Perl pronoun,<tt class="literal">@_</tt>, which means "them".  The arguments to afunction always come in as "them".  The <tt class="literal">shift</tt>operator knows to operate on <tt class="literal">@_</tt> if you omit it,just as the ride operator at Disneyland might call out "Next!" withoutspecifying which queue is supposed to shift.  (There's no point inspecifying, because there's only one queue that matters.)</p><p>The <tt class="literal">||</tt> can be used to set defaults despite itsorigins as a Boolean operator, since Perl returns the first truevalue.  Perl programmers often manifest a cavalier attitude toward thetruth; the line above would break if, for instance, you tried tospecify a quantity of 0.  But as long as you never want to set either<tt class="literal">$quality</tt> or <tt class="literal">$quantity</tt> to a falsevalue, the idiom works great.  There's no point in getting allsuperstitious and throwing in calls to <tt class="literal">defined</tt> and<tt class="literal">exists</tt> all over the place.  You just have tounderstand what it's doing.  As long as it won't accidentally befalse, you're fine.</p></li><li><p> Useassignment forms of operators, including control flow operators:<blockquote><pre class="programlisting">$xval = $cache{$x} ||= expensive($x);</pre></blockquote>Here we don't initialize our cache at all.  We just rely on the<tt class="literal">||=</tt> operator to call<tt class="literal">expensive($x)</tt> and assign it to<tt class="literal">$cache{$x}</tt> only if <tt class="literal">$cache{$x}</tt> isfalse.  The result of that is whatever the new value of<tt class="literal">$cache{$x}</tt> is.  Again, we take the cavalierapproach towards truth, in that if we cache a false value,<tt class="literal">expensive($x)</tt> will get called again.  Maybe theprogrammer knows that's okay, because <tt class="literal">expensive($x)</tt>isn't expensive when it returns false.  Or maybe the programmer knowsthat <tt class="literal">expensive($x)</tt> never returns a false value atall.  Or maybe the programmer is just being sloppy.  Sloppiness can beconstrued as a form of creativity.</p></li><li><p> Use loop controls as operators, not just asstatements. And...</p></li><li><p> Use commaslike small semicolons:<blockquote><pre class="programlisting">while (&lt;&gt;) {    $comments++, next if /^#/;    $blank++, next    if /^\s*$/;    last              if /^__END__/;    $code++;}print "comment = $comments\nblank = $blank\ncode = $code\n";</pre></blockquote>This shows an understanding that statement modifiersmodify statements, while <tt class="literal">next</tt> is a mere operator.  It also showsthe comma being idiomatically used to separate expressions much likeyou'd ordinarily use a semicolon.  (The difference being that thecomma keeps the two expressions as part of the same statement, under thecontrol of the single statement modifier.)</p></li><li><p>Use flow control to your advantage:<blockquote><pre class="programlisting">while (&lt;&gt;) {    /^#/       and $comments++, next;    /^\s*$/    and $blank++, next;    /^__END__/ and last;    $code++;}print "comment = $comments\nblank = $blank\ncode = $code\n";</pre></blockquote>Here's the exact same loop again, only this time with the patterns out in front.  Theperspicacious Perl programmer understands that it compiles down to exactly thesame internal codes as the previous example.  The <tt class="literal">if</tt> modifier isjust a backward <tt class="literal">and</tt> (or <tt class="literal">&amp;&amp;</tt>) conjunction, and the <tt class="literal">unless</tt>modifier is just a backward <tt class="literal">or</tt> (or <tt class="literal">||</tt>) conjunction.</p></li><li><p>Use the implicit loops provided by the <span class="option">-n</span> and <span class="option">-p</span> switches.</p></li><li><p>Don't put semicolon at the end of a one-line block:<blockquote><pre class="programlisting">#!/usr/bin/perl -n$comments++, next LINE if /#/;$blank++, next LINE    if /^\s*$/;last LINE              if /^__END__/;$code++;END { print "comment = $comments\nblank = $blank\ncode = $code\n" }</pre></blockquote>This is essentially the same program as before.  We put an explicit<tt class="literal">LINE</tt> label on the loop control operators because we felt like it, butwe didn't really need to, since the implicit <tt class="literal">LINE</tt> loop supplied by <tt class="userinput"><b>-n</b></tt> is the innermostenclosing loop.  We used an <tt class="literal">END</tt> to get the final print statementoutside the implicit main loop, just as in <em class="emphasis">awk</em>.</p></li><li><p>Use here docs when the printing gets ferocious.</p></li><li><p>Use a meaningful delimiter on the here doc:<blockquote><pre class="programlisting">END { print &lt;&lt;"COUNTS" }comment = $commentsblank = $blankcode = $codeCOUNTS</pre></blockquote>Rather than using multiple prints, the fluent Perl programmer uses amultiline string with interpolation.  And despite our calling it aCommon Goof earlier, we've brazenly left off the trailingsemicolon because it's not necessary at the end of the <tt class="literal">END</tt> block.  (If weever turn it into a multiline block, we'll put the semicolon back in.)</p></li><li><p>Do substitutions and translations en passant on a scalar:<blockquote><pre class="programlisting">($new = $old) =~ s/bad/good/g;</pre></blockquote>Since lvalues are lvaluable, so to speak, you'll often see peoplechanging a value "in passing" while it's being assigned.  This couldactually save a string copy internally (if we ever get around toimplementing the optimization):<blockquote><pre class="programlisting">chomp($answer = &lt;STDIN&gt;);</pre></blockquote>Any function that modifies an argument in place can do the en passanttrick.  But wait, there's more!</p></li><li><p>Don't limit yourself to changing scalars en passant:<blockquote><pre class="programlisting">for (@new = @old) { s/bad/good/g }</pre></blockquote>Here we copy <tt class="literal">@old</tt> into <tt class="literal">@new</tt>, changing everything in passing(not all at once, of course--the block is executed repeatedly, one "it" at a time).</p></li><li><p>Pass named parameters using the fancy <tt class="literal">=&gt;</tt> comma operator.</p></li><li><p>Rely on assignment to a hash to do even/odd argument processing:

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一级二级在线观看| 成人国产精品免费观看动漫| 亚洲午夜国产一区99re久久| 综合久久久久综合| av在线一区二区| 欧美一区二区福利视频| 蜜桃av一区二区三区| 五月激情综合色| 香蕉成人啪国产精品视频综合网 | 国产精品久久久久久久裸模| 日韩精品一区二区在线观看| 日韩一区二区三区电影在线观看| 欧美一区二视频| 欧美videos中文字幕| 久久精品亚洲精品国产欧美kt∨| 欧美激情中文字幕| 亚洲卡通动漫在线| 日韩国产高清在线| 国产一二三精品| 色女孩综合影院| 91精品国产欧美一区二区| 精品久久免费看| 亚洲乱码中文字幕| 免费在线观看视频一区| 国产成人在线网站| 欧美日韩一区久久| 久久免费看少妇高潮| 亚洲欧美日韩久久精品| 日本最新不卡在线| 成人激情文学综合网| 欧美日韩精品电影| 国产精品人妖ts系列视频| 午夜亚洲福利老司机| 国产激情一区二区三区桃花岛亚洲| 欧美一级在线免费| 国产精品久久久久久久久图文区| 午夜精品久久久久久| 国产91精品精华液一区二区三区 | 蜜臀精品一区二区三区在线观看| 国产传媒一区在线| 制服丝袜国产精品| 中文字幕一区二区三区色视频| 日韩黄色在线观看| 99久久er热在这里只有精品15 | 日韩欧美色电影| 亚洲欧美区自拍先锋| 国产精品 欧美精品| 6080日韩午夜伦伦午夜伦| 国产精品成人免费在线| 国产做a爰片久久毛片| 欧美日韩一区三区| 亚洲精品水蜜桃| 懂色av一区二区在线播放| 欧美一区二区三区四区久久| 亚洲午夜久久久久久久久久久 | 亚洲成av人**亚洲成av**| 成人毛片老司机大片| 久久婷婷成人综合色| 日韩精品五月天| 欧美性生活一区| 国产精品天天看| 国产成人精品网址| 久久久一区二区| 精品亚洲免费视频| 欧美成人一级视频| 精品在线播放免费| 欧美一级国产精品| 免费欧美高清视频| 日韩精品自拍偷拍| 九一九一国产精品| 精品日韩一区二区三区免费视频| 日本视频免费一区| 日韩欧美一级在线播放| 轻轻草成人在线| 欧美大尺度电影在线| 国产精品亚洲成人| 中文字幕乱码一区二区免费| 国产99久久久久| 综合色中文字幕| 色婷婷综合久色| 亚洲一区二区欧美激情| 欧美高清视频一二三区 | 免费成人性网站| 欧美一二区视频| 激情综合色播激情啊| 国产午夜精品一区二区| 国产成人在线色| 18成人在线观看| 欧美私人免费视频| 蜜臀精品一区二区三区在线观看 | 国产精品1区二区.| 国产日产欧美精品一区二区三区| 国产精品一区三区| 亚洲欧洲av在线| 欧美日韩aaaaaa| 久久国产尿小便嘘嘘尿| 欧美激情在线免费观看| 91老师片黄在线观看| 日韩高清在线观看| 国产日产欧美精品一区二区三区| 色综合网色综合| 日韩二区三区在线观看| 国产欧美日韩视频一区二区| 日本精品视频一区二区三区| 午夜私人影院久久久久| 国产女人aaa级久久久级| 91国产视频在线观看| 国内外成人在线视频| 亚洲欧洲综合另类| 日韩欧美国产一区在线观看| 成人ar影院免费观看视频| 亚洲国产wwwccc36天堂| 精品国产乱码久久久久久老虎| 99久久久久久99| 免费不卡在线视频| 亚洲四区在线观看| 日韩一级黄色大片| 99riav一区二区三区| 日韩国产精品91| 亚洲欧美日韩系列| 国产喂奶挤奶一区二区三区| 欧美日本一道本在线视频| 成人精品一区二区三区四区 | 欧美一区二区在线免费播放| 成人午夜av影视| 美女诱惑一区二区| 亚洲黄色小视频| 欧美国产日韩亚洲一区| 日韩欧美高清一区| 欧美理论在线播放| 色综合色综合色综合色综合色综合| 韩国视频一区二区| 天天综合网天天综合色| 亚洲欧美日韩国产综合| 日本一区二区成人在线| 欧美精品一区二区三区蜜桃视频 | 岛国精品在线观看| 蜜桃免费网站一区二区三区| 亚洲国产aⅴ成人精品无吗| 亚洲天堂久久久久久久| 国产精品免费人成网站| 国产免费成人在线视频| wwww国产精品欧美| 精品三级在线观看| 欧美videos中文字幕| 欧美va亚洲va香蕉在线| 欧美一区二区三区喷汁尤物| 欧美三级在线看| 欧美日韩一区小说| 欧美日韩国产精选| 欧美日韩国产高清一区| 欧美日韩国产美女| 欧美一区二区三级| 日韩一区二区免费电影| 欧美tickling挠脚心丨vk| 日韩欧美亚洲一区二区| 亚洲国产视频在线| 午夜精品一区二区三区三上悠亚 | 中日韩免费视频中文字幕| 国产亚洲精品精华液| 国产精品每日更新在线播放网址| 国产精品不卡在线| 一区二区成人在线| 午夜不卡在线视频| 免费人成网站在线观看欧美高清| 久久99久久久欧美国产| 国产精品性做久久久久久| 成人午夜在线播放| 91国产成人在线| 欧美一区欧美二区| 国产欧美精品一区二区三区四区| 中文字幕一区二区三区不卡在线 | 99久久综合狠狠综合久久| 91网站黄www| 欧美日韩一区二区在线观看| 欧美一二三四区在线| 亚洲国产成人一区二区三区| 一区二区三区中文免费| 日本不卡视频一二三区| 福利视频网站一区二区三区| 色网站国产精品| 日韩精品一区二区三区视频播放 | 亚洲成人福利片| 另类中文字幕网| www.欧美色图| 欧美日韩夫妻久久| 中文字幕不卡在线| 午夜久久福利影院| 成人丝袜视频网| 欧美一区午夜视频在线观看| 欧美国产一区视频在线观看| 日日欢夜夜爽一区| 波多野结衣精品在线| 在线播放91灌醉迷j高跟美女| 国产婷婷色一区二区三区四区 | 国产原创一区二区三区| 色婷婷一区二区三区四区| 欧美mv日韩mv| 午夜精品123| 91日韩精品一区|