«ÖáçÒñ Template Toolkit : £·¢Ð·Öå¨Æ· ¦ÐÞ á ¢Öåñ ã õ ¢ÐÖÔ Ò· ë Perl http://forum.template-toolkit.ru/view_forum/forum_id-8.html?rss Template Toolkit - ¢ñãåá Þ, ÒÖùÔ Þ · á ãõ·áÞ¨Ò Þ ã·ãå¨Ò  ֢ᠢÖåÆ· õ ¢ÐÖÔÖë. Õ  ã ½å¨ á ¢Öå ¨å ªÖáçÒ, ë ÆÖåÖáÖÒ Ö¢ãç馠œåãÞ ëÖØáÖãñ ·ãØÖÐíóÖë Ô·Þ ¢·¢Ð·Öå¨Æ· ØÖ á ¢Öå¨ ã õ ¢ÐÖÔ Ò·. Text::Template, HTML::Template, Mason · ¦á笷¨ ¢·¢Ð·Öå¨Æ· ru Lobanov Igor Lobanov Igor <webmaster@template-toolkit.ru> Thu, 17 Mar 2005 12:03:32 GMT Wed, 4 Jan 2006 02:29:01 GMT Perl script, Template Toolkit http://forum.template-toolkit.ru/images/tt2powered.gif Template Toolkit - õ ¢ÐÖÔñ ë perl http://forum.template-toolkit.ru/ 88 31 http://blogs.law.harvard.edu/tech/rss http://forum.template-toolkit.ru/view_topic/topic_id-53.html?rss Tue, 28 Dec 2004 19:07:19 GMT â ó¦¨Ð¨Ô·¨ ÆÖ¦ , Øᨦãå ëШԷÞ, · ÆÖÔª·¬çá ¤·· http://forum.template-toolkit.ru/view_topic/topic_id-53.html?rss Õ  <a target="_blank" href="http://www.theperlreview.com/">Perl Review</a> ÖØç¢Ð·ÆÖë Ô  ãå åíÞ £á ½ Ô  ¦¨ «ÖÞ (brian d foy) &quot;Separating Code, Presentation, and Configuration&quot;. Õ·é¨ Øá·ëÖ¦·åãÞ Ø¨á¨ëÖ¦ ãå åí·.<br /><br /><span style="font-weight:bold">Çá åÆ·½ Ö¢óÖá.</span><br /><br />à ëóÞÐ ØáÖ¬á ÒÒç ·ó Øᨦñ¦çù¨½ ãå åí· · á ó¦¨Ð·Ð ÆÖ¦, Øᨦãå ëШԷ¨ · ÆÖÔª·¬çá ¤·œ, ûåÖ¢ñ 㦨Рåí ØáÖ¬á ÒÒç ¢ÖШ¨ ¬·¢ÆÖ½ · Ш¬ÆÖ½ ¦ÐÞ ØÖ¦¦¨áéÆ·.<br /><br /><span style="font-weight:bold">1. ì먦¨Ô·¨.</span><br /><br />ì ØÖãШ¦Ô¨Ò ëñØçãƨ Þ Øᨦãå ë·Ð ØáÖ¬á ÒÒç, ÆÖåÖáçœ Þ ·ãØÖÐíóçœ ¦ÐÞ åÖ¬Ö, ûåÖ¢ñ ó ¢·á åí · ÖåÖ¢á é åí Rich Site Summaries (RSS) ã ¦á笷µ 먢-ã ½åÖë<span style="font-weight:bold"><sup>1</sup></span>. ì ÆÖ¦¨ Þ ·ãØÖÐíóÖë Ð зå¨á ÐíÔñ¨ ë¨Ð·û·Ôñ, ûåÖ¢ñ çÆ ó åí Æ Æ·¨ ª ½Ðñ ó ¬áçé åí · Æ Æ Øᨦãå ëÐÞåí ¦ ÔÔñ¨, · Ö¢¨ù Ð ûåÖ ë ÷åÖÒ ëñØçãƨ Þ ÷åÖ ·ãØá ëÐœ.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 1</span> ãÖ¦¨áé·å ØáÖ¬á ÒÒç, ÆÖåÖáçœ Þ Øᨦãå ëÐÞÐ ë Øᨦñ¦çù¨Ò ëñØçãƨ. ì Ò ãã·ë¨ <span style="font-weight:bold">@files</span> µá ÔÞåãÞ ª ½Ðñ, ÆÖåÖáñ¨ Ô¨Ö¢µÖ¦·ÒÖ ó ¬áçó·åí, <span style="font-weight:bold">$base</span> - Æ å ÐÖ¬, ¬¦¨ ãÖµá ÔÞ¨åãÞ ëñëÖ¦, · Ô¨ãÆÖÐíÆÖ ëñá é¨Ô·½ <span style="font-weight:bold">print</span> ãÖó¦ œå HTML ã ØÖ¦ãå ÔÖëÆÖ½ ØáÖãåñµ بá¨Ò¨ÔÔñµ (ûåÖ ØᨦØÖûå·å¨ÐíÔ¨¨ ãÆ é¨Ò û¨Ò ·ãØÖÐíóÖë åí HTML-ªçÔƤ·· ÒÖ¦çÐÞ CGI). øåÖ Ô¨¬·¢Æ·½ · åáç¦Ôñ½ ¦ÐÞ ãÖØáÖëÖé¦¨Ô·Þ ÆÖ¦. ÇÖ¬¦  Þ ó µÖûç ØÖÒ¨ÔÞåí ãØ·ãÖÆ ã ½åÖë ·Ð· ëñëÖ¦, Þ á·ãÆçœ ãÐÖÒ åí ØáÖ¬á ÒÒç, ¨ãз Ô ¢¨áç ûåÖ-åÖ Ô¨Øá ë·ÐíÔÖ ·Ð· 㦨Рœ ¦áç¬çœ Öõ·¢Æç.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 1: ô ¬áçóû·Æ RSS ã é¨ãåÆÖØáÖØ·ã ÔÔñÒ· óÔ û¨Ô·ÞÒ·.</span><br /><div class="code"><pre>1 #!/usr/bin/perl -w 2 use strict; 3 4 use LWP::Simple; 5 use XML::RSS; 6 7 my @files = qw( 8 http://use.perl.org/useperl.rss 9 http://search.cpan.org/rss/search.rss 10 http://jobs.perl.org/rss/standard.rss 11 http://www.perl.com/pace/perlnews.rdf 12 http://www.perlfoundation.org/perl-foundation.rdf 13 http://www.stonehenge.com/merlyn/UnixReview/ur.rss 14 http://www.stonehenge.com/merlyn/WebTechniques/wt.rss 15 http://www.stonehenge.com/merlyn/LinuxMag/lm.rss 16 ); 17 18 my $base = '/usr/home/comdog/TPR/rss-html'; 19 20 foreach my $url ( @files ) 21 { 22 my $file = $url; 23 24 $file =~ s|.*/||; 25 26 my $result = open my $fh, &quot;&gt; $base/$file.html&quot;; 27 28 unless( $result ) 29 { 30 warn &quot;Could not open [$file] for writing! $!&quot;; 31 next; 32 } 33 34 select $fh; 35 36 my $rss = XML::RSS-&gt;new(); 37 my $data = get( $url ); 38 $rss-&gt;parse( $data ); 39 40 my $channel = $rss-&gt;{channel}; 41 my $image = $rss-&gt;{image}; 42 43 print &lt;&lt;&quot;HTML&quot;; 44 &lt;table cellpadding=1&gt;&lt;tr&gt;&lt;td bgcolor=&quot;#000000&quot;&gt; 45 &lt;table cellpadding=5&gt; 46 &lt;tr&gt;&lt;td bgcolor=&quot;#aaaaaa&quot; align=&quot;center&quot;&gt; 47 HTML 48 49 if( $image-&gt;{url} ) 50 { 51 my $img = qq|&lt;img src=&quot;$$image{url}&quot; alt=&quot;$$channel{title}&quot;&gt;|; 52 print qq|&lt;a href=&quot;$$channel{link}&quot;&gt;$img&lt;/a&gt;&lt;br&gt;\n|; 53 } 54 else 55 { 56 print qq|&lt;a href=&quot;$$channel{link}&quot;&gt;$$channel{title}&lt;/a&gt;&lt;br&gt;\n|; 57 } 58 59 print &lt;&lt;&quot;HTML&quot;; 60 &lt;font size=&quot;-1&quot;&gt;$$channel{description}&lt;/font&gt; 61 &lt;/td&gt;&lt;/tr&gt; 62 &lt;tr&gt;&lt;td bgcolor=&quot;#bbbbff&quot; width=200&gt;&lt;font size=&quot;-1&quot;&gt; 63 HTML 64 65 foreach my $item ( @{ $rss-&gt;{items} } ) 66 { 67 print qq|&lt;b&gt;&gt;&lt;/b&gt;&lt;a href=&quot;$$item{link}&quot;&gt;$$item{title}&lt;/a&gt;&lt;br&gt;&lt;br&gt;\n|; 68 } 69 70 print &lt;&lt;&quot;HTML&quot;; 71 &lt;/font&gt;&lt;/td&gt;&lt;/tr&gt; 72 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; 73 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; 74 HTML 75 76 close $fh; 77 }</pre></div><br /><br /><span style="font-weight:bold">2. ×妨ШԷ¨ Øᨦãå ëШԷÞ.</span><br /><br />¶ÖáÖõ·½ ¦·ó ½Ô Ô¨ ãëÞóñë ¨å ã¨¢Þ ã û ãåÔñÒ Øᨦãå ëШԷ¨Ò ¦ ÔÔñµ. ÓÖÞ ØáÖ¬á ÒÒ  ¦ÖÐéÔ  ó ¢á åí ¦ ÔÔñ¨ · 㦨Рåí ·µ ¦ÖãåçØÔñÒ· û¨Òç-åÖ, ûåÖ ·µ Øᨦãå ëÐÞ¨å - åÖ, ûåÖ Þ á ¢Öå œ ã RSS Ô¨ ¦ÖÐéÔÖ ·Ò¨åí óÔ û¨Ô·Þ. à ÒÖ¬ç ó µÖå¨åí ØáÖ·óëÖ¦·åí HTML, TeX, ØáÖãåÖ½ å¨Æãå, ·Ð· ¦ é¨ Æ ÆÖ½-åÖ ªÖáÒ å, ÆÖåÖáñ½ Ô¨ ÒÖ¬ç 㨢¨ Øᨦãå ë·åí.<br /><br />ìÖóÒÖéÔÖ ÆåÖ-åÖ ó µÖû¨å Ô Ø·ã åí ãÖ¢ãåë¨ÔÔçœ ã·ãå¨Òç ¦ÐÞ á ¢Öåñ ã õ ¢ÐÖÔ Ò·, ÔÖ ÒÔ¨ Ôá ë·åãÞ ÒÖ¦çÐí Text::Template Ó áÆ -§é¨½ãÖÔ  §ÖÒ·Ôçã  (Mark-Jason Dominus). ×Ô ¦¨Ð ¨å ë㨠ûåÖ ÒÔ¨ Ô¨Ö¢µÖ¦·ÒÖ, Ô¨ åᨢç¨å ¦ÐÞ ãëÖ¨½ á ¢Öåñ ¦ÖØÖÐÔ·å¨ÐíÔñµ ØáÖ¬á ÒÒ · Ô Ø·ã Ô ØÖÐÔÖãåíœ Ô  Perl. è Ô¨¬Ö ØáÖãåÖ½ ·Ôå¨áª¨½ã · ÒÔ¨ Ô¨ åᨢç¨åãÞ ·óçû åí ÞóñÆ õ ¢ÐÖÔÖë, ØÖãÆÖÐíÆç õ ¢ÐÖÔñ ·ãØÖÐíóçœå Perl.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 2</span> - ÷åÖ å  é¨ ØáÖ¬á ÒÒ , åÖÐíÆÖ ëÒ¨ãåÖ ëÔ¨¦á¨ÔÔÖ¬Ö HTML ·ãØÖÐíóç¨åãÞ Text::Template. ì ãåáÖƨ 5 Þ ·ÒØÖáå·áçœ Ò¨åÖ¦ fill_in_file(). ì ãåáÖƨ 13 çÆ óñë œ õ ¢ÐÖÔ, ÆÖåÖáñ½ ¢ç¦ç ·ãØÖÐíóÖë åí. ì¨ãí HTML, ·ãØÖÐíóç¨Òñ½ ØáÖ¬á ÒÒÖ½, å¨Ø¨áí ëñÔ¨ã¨Ô ë ª ½Ð õ ¢ÐÖÔ , Øá·ë¨¦¨ÔÔñ½ ë <span style="font-style:italic">зãå·Ô¬¨ 3</span>.<br /><br />ÓÖ¦çÐí Text::Template ÒÖé¨å Øá·Ô·Ò åí ¦ ÔÔñ¨ Æ Æ µ¨õ. ÇÐœû· µ¨õ  ãå ÔÖëÞåãÞ ·Ò¨Ô Ò· بá¨Ò¨ÔÔñµ ë õ ¢ÐÖÔ¨,   óÔ û¨Ô·Þ - óÔ û¨Ô·ÞÒ· بá¨Ò¨ÔÔñµ õ ¢ÐÖÔ ,   å Æé¨ ÖØᨦ¨ÐÞœå å·Ø بá¨Ò¨ÔÔñµ. ©ãз óÔ û¨Ô·¨ µ¨õ  ØáÖãåÖ½ ãÆ ÐÞá, بá¨Ò¨ÔÔ Þ õ ¢ÐÖÔ  ãÆ ÐÞá. ©ãз óÔ û¨Ô·¨ µ¨õ  -  ÔÖÔ·ÒÔñ½ Ò ãã·ë, بá¨Ò¨ÔÔ Þ õ ¢ÐÖÔ  - Ò ãã·ë, · å Æ ¦ Ð¨¨.<br /><br />×¢ž¨Æå, ãÖó¦ ë ¨Òñ½ XML::RSS -  ÔÖÔ·ÒÔñ½ µ¨õ. ÓÖ¦çÐí ØᨦÖãå ëÐÞ¨å  ¢ãåá ÆåÔñ½ ·Ôå¨áª¨½ã ¦ÐÞ ãÖó¦ Ô·Þ, ÔÖ Ô¨ ¦ÐÞ ¦ÖãåçØ . øåÖ Öåû ãå· ·Ò¨ÔÔÖ åÖ, ûåÖ Þ ¦ÖÐé¨Ô بᨦ åí ÒÖ¨Òç õ ¢ÐÖÔç. ì õ ¢ÐÖÔ¨ <span style="font-weight:bold">$rss-&gt;channel</span>, ÆÖåÖá Þ ë Æ û¨ãåë¨ óÔ û¨Ô·Þ ãÖ¦¨áé·å  ÔÖÔ·ÒÔñ½ µ¨õ, ãå ÔÖë·åãÞ <span style="font-weight:bold">%channel</span>,   <span style="font-weight:bold">$rss-&gt;items</span>, ãÖ¦¨áé ù Þ  ÔÖÔ·ÒÔñ½ Ò ãã·ë ãå ÔÖë·åãÞ <span style="font-weight:bold">@items</span>.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 2: ¸ãØÖÐíóÖë Ô·¨ õ ¢ÐÖÔ .</span><br /><div class="code"><pre>1 #!/usr/bin/perl -w 2 use strict; 3 4 use LWP::Simple; 5 use Text::Template qw(fill_in_file); 6 use XML::RSS; 7 8 my @files = qw( 9 http://use.perl.org/useperl.rss 10 ); 11 12 my $base = '.'; 13 my $template = 'rss-html.tmpl'; 14 15 foreach my $url ( @files ) 16 { 17 my $file = $url; 18 19 $file =~ s|.*/||; 20 21 my $result = open my $fh, &quot;&gt; $base/$file.html&quot;; 22 23 unless( $result ) 24 { 25 warn &quot;Could not open [$file] for writing! $!&quot;; 26 next; 27 } 28 29 my $rss = XML::RSS-&gt;new(); 30 my $data = get( $url ); 31 $rss-&gt;parse( $data ); 32 33 print fill_in_file( $template, HASH =&gt; $rss ); 34 close $fh; 35 }</pre></div><br /><br />ìÔçåá· õ ¢ÐÖÔ  Text::Template ·ãØÖÐÔÞ¨å ¢ÐÖÆ· ÆÖ¦ , ÆÖåÖáñ¨ ÖÔ Ô µÖ¦·å Ò¨é¦ç ª·¬çáÔñÒ· ãÆ֢Ơҷ. ×Ô ó Ò¨ÔÞ¨å ¢ÐÖÆ ØÖãШ¦Ô·Ò ëñû·ãШÔÔñÒ ëñá é¨Ô·¨Ò. ¸Ò¨Ô  بá¨Ò¨ÔÔñµ - ÆÐœû· µ¨õ , ããñÐÆç Ô  ÆÖåÖáñ½ Þ Ø¨á¨¦ Ð ë Æ û¨ãåë¨  á¬çÒ¨Ôå  ªçÔƤ·· fill_in_file() ë ÆÖ¦¨, Øá·ë¨¦¨ÔÔÖÒ ë <span style="font-style:italic">зãå·Ô¬¨ 2</span>.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 3: HTML õ ¢ÐÖÔ.</span><br /><div class="code"><pre>1 &lt;table cellpadding=1&gt;&lt;tr&gt;&lt;td bgcolor=&quot;#000000&quot;&gt; 2 &lt;table cellpadding=5&gt; 3 &lt;tr&gt; 4 &lt;td bgcolor=&quot;#aaaaaa&quot; align=&quot;center&quot;&gt; 5 &lt;a href=&quot;{ $channel{link} }&quot;&gt;{ 6 7 $image ? qq|&lt;img src=&quot;$image&quot; alt=&quot;$channel{title}&quot;&gt;| : $channel{title} 8 9 }&lt;/a&gt;&lt;br&gt; 10 11 { $channel{description} } 12 &lt;/td&gt; 13 &lt;/tr&gt; 14 15 &lt;tr&gt; 16 &lt;td bgcolor=&quot;#bbbbff&quot; width=200&gt;&lt;font size=&quot;-1&quot;&gt; 17 { 18 my $str; 19 20 foreach my $item ( @items ) 21 { 22 $str .= qq|&lt;b&gt;&gt;&lt;/b&gt;&lt;a href=&quot;$$item{link}&quot;&gt;$$item{title}&lt;/a&gt;&lt;br&gt;&lt;br&gt;\n|; 23 } 24 25 $str; 26 }&lt;/font&gt;&lt;/td&gt; 27 &lt;/tr&gt; 28 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; 29 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</pre></div><br /><br />Ç Æ åÖÐíÆÖ ã·ãå¨Ò  õ ¢ÐÖÔÖë 󠦨½ãåÖë Ô , Þ ÒÖ¬ç Ò¨ÔÞåí Øᨦãå ëШԷ¨ Ô¨ Ò¨ÔÞÞ ÐÖ¬·Æç ÆÖ¦ . ©ãз Þ Øá·Òç á¨õ¨Ô·¨ ·óÒ¨Ô·åí ë·¦ Øᨦãå ëÐ¨Ô·Þ ¦ ÔÔñµ, Þ ØÖÒ¨ÔÞœ åÖÐíÆÖ õ ¢ÐÖÔ. ©ãз ÒÔ¨ ëÒ¨ãåÖ HTML åᨢç¨åãÞ ØáÖãåÖ½ å¨Æãå, Þ åÖÐíÆÖ ·óÒ¨Ôœ ØÖ¦ ÔÖëñ½ ªÖáÒ å õ ¢ÐÖÔ, Æ Æ ÷åÖ ã¦¨Ð ÔÖ ë <span style="font-style:italic">зãå·Ô¬¨ 4</span>.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 4: ö ¢ÐÖÔ ¦ÐÞ Ö¢ñûÔÖ¬Ö å¨Æãå .</span><br /><div class="code"><pre>1 { $channel{title} } 2 3 { $channel{description} } 4 5 { 6 my $str; 7 8 foreach my $item ( @items ) 9 { 10 $str .= qq|* $$item{title}\n|; 11 } 12 13 $str; 14 }</pre></div><br /><br /><span style="font-weight:bold">3. ×妨ШԷ¨ ÆÖÔª·¬çá ¤··.</span><br /><br />¶ÖáÖõ·½ ¦·ó ½Ô å Æé¨ ØÖóëÖÐÞ¨å  ¦ Øå·áÖë åí ãÆá·Øå Æ á óзûÔÖÒç ÖÆáçé¨Ô·œ. ì <span style="font-style:italic">зãå·Ô¬¨ 1</span> Þ é¨ãåÆÖ ØáÖØ·ã Ð óÔ û¨Ô·¨ ¦·á¨ÆåÖá·· ¦ÐÞ ëñëÖ¦ , ûåÖ ¦¨Ð ¨å ÒÖ½ ãÆá·Øå µáçØÆ·Ò - ¨ãз ÒÖÞ ¦ÖÒ õÔÞÞ ¦·á¨ÆåÖá·Þ ØÖÒ¨ÔÞ¨åãÞ, ãÆá·Øå ãÐÖÒ ¨åãÞ. ÇáÖÒ¨ åÖ¬Ö <span style="font-style:italic">ë зãå·Ô¬¨ 2</span> é¨ãåÆÖ ØáÖØ·ã ÔÖ ·ÒÞ õ ¢ÐÖÔ , Ô¨ãÒÖåáÞ Ô  åÖ ûåÖ Þ ÒÖ¬ç Ò¨ÔÞåí Øᨦãå ëШԷ¨, ·óÒ¨ÔÞÞ õ ¢ÐÖÔ. ÓÔ¨ ÔçéÔÖ ·Ò¨åí ëÖóÒÖéÔÖãåí ¦ ë åí Æ é¦ÖÒç õ ¢ÐÖÔç ãÖ¦¨áé å¨ÐíÔÖ¨ ·ÒÞ ëÒ¨ãåÖ ·ãØÖÐíóÖë Ô·Þ Ö¦ÔÖ¬Ö · åÖ¬Ö é¨ ·Ò¨Ô· ¦ÐÞ á óÔÖ¬Ö ãÖ¦¨áé·ÒÖ¬Ö.<br /><br />ÓÔÖ¬·¨ ãëÖ¢Ö¦ÔÖ-¦ÖãåçØÔñ¨ ãÆá·Øåñ, ÆÖåÖáñ¨ Þ Ô õ¨Ð ë ¸Ôå¨áÔ¨å åᨢçœå, ûåÖ¢ñ ØÖÐíóÖë å¨Ðí Öåᨦ Æå·áÖë Ð ë¨áµÔœœ û ãåí ãÆá·Øå  ·Ð· ëÆÐœû ¨Òçœ ¢·¢Ð·Öå¨Æç, ÆÖåÖá Þ ãÖ¦¨áé·å åÖÐíÆÖ ÆÖÔª·¬çá ¤·ÖÔÔñ¨ ¦ ÔÔñ¨. æ ÆÖ½ ØÖ¦µÖ¦ åᨢç¨å, ûåÖ¢ñ ÆÖÔ¨ûÔñ½ ØÖÐíóÖë å¨Ðí óÔ Ð ÖãÔÖëñ ÞóñÆ  ØáÖ¬á ÒÒ·áÖë Ô·Þ · Øá ë·Ð ãÆá·Øå - Öõ·¢Æ  ãÐÖÒ ¨å ãÆá·Øå. ÝÐÖµ·¨ ÆÖÔª·¬çá ¤·ÖÔÔñ¨ ¦ ÔÔñ¨ ÒÖ¬çå Øá·ë¨ãå· Æ Ô¨Öé·¦ ÔÔñÒ á¨óçÐíå å Ò, ÔÖ ÖÔ· Ô¨ ØÖÐÖÒ œå ØáÖ¬á ÒÒç.<br /><br />à ÒÖ¬ç çÆ ó åí å¨Æçù·¨ ÆÖÔª·¬çá ¤·ÖÔÔñ¨ ¦ ÔÔñ¨ Ô¨ãÆÖÐíÆ·Ò· ãØÖãÖ¢ Ò· · ØÖÆ éç åÖÐíÆÖ Ö¦·Ô ·ó Ô·µ. ¡áµ·ë Comprehensive Perl Archive Network (CPAN)<span style="font-weight:bold"><sup>2</sup></span> ãÖ¦¨áé·å Ô¨ãÆÖÐíÆÖ ÒÖ¦çШ½ ¦ÐÞ á ó¢Öá  ÆÖÔª·¬çá ¤·ÖÔÔñµ ª ½ÐÖë ë á óзûÔñµ ªÖáÒ å µ ·Ð·  á¬çÒ¨ÔåÖë ÆÖÒ Ô¦ÔÖ½ ãåáÖÆ·. §·ó ½Ô¨áñ ¦ÖÐéÔñ ëñ¢·á åí ØÖ¦µÖ¦, ÆÖåÖáñ½ ç¦ÖëШåëÖáÞ¨å ·µ Ôç馠Ò.<br /><br />ÇÖ¬¦  Þ ëبáëñ¨ Ô û Ð Ö妨ÐÞåí ¦ ÔÔñ¨ ÆÖÔª·¬çá ¤·· Öå ÒÖ·µ ãÆá·ØåÖë, Þ Ø¨á¨¢á Ð Ô¨ãÆÖÐíÆÖ ÒÖ¦çШ½ Ô  CPAN · Öãå ÔÖë·ÐãÞ Ô  ConfigReader::Simple, ÆÖåÖáñ½ ·ãØÖÐíóç¨å ØÖãåáÖûÔñ½ ªÖáÒ å ÆÐœû-óÔ û¨Ô·¨. à ·ãØÖÐíóÖë Ð ¨¬Ö Ô ãåÖÐíÆÖ û ãåÖ, ûåÖ Ô û Ð ÖåØá ëÐÞåí ÒÖ· ·óÒ¨Ô¨Ô·Þ £¨Æç ×¢¨á·Ôç (Bek Oberin),  ëåÖáç Öá·¬·Ô ÐíÔÖ½ ë¨áã··, ó å¨Ò ØÖÐÔÖãåíœ ëóÞÐ Ô  ã¨¢Þ ØÖ¦¦¨áéÆç ÒÖ¦çÐÞ.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 5</span>  ¦ Øå·áç¨å <span style="font-style:italic">зãå·Ô¬ 2</span> Æ ·ãØÖÐíóÖë Ô·œ ConfigReader::Simple. à ãÖó¦ œ ÔÖëñ½ Ö¢ž¨Æå ÆÖÔª·¬çá ¤··, ó å¨Ò û·å œ óÔ û¨Ô·Þ ·ó Ö¢ž¨Æå . ÓÖ¦çÐí Øá¨Ö¢á óç¨å ·Ò¨Ô  ÆÐœû¨½ ÆÖÔª·¬çá ¤·· ë ·Ò¨Ô  Ò¨åÖ¦Öë ¦ÐÞ ØáÖãåÖ¬Ö ¦ÖãåçØ  (µÖåÞ ¦ÐÞ ¦ÖãåçØ  Æ óÔ û¨Ô·ÞÒ ÆÐœû¨½ ã ÷ÆóÖå·û¨ãÆ·Ò· ·Ò¨Ô Ò·, ÆÖåÖáñ¨ Ô¨ ÒÖ¬çå ¢ñåí Øá¨Ö¢á óÖë Ôñ ë ·¦¨Ôå·ª·Æ åÖáñ Perl Øá·µÖ¦·åãÞ ·ãØÖÐíóÖë åí Ò¨åÖ¦ get()). <span style="font-style:italic">Ñ·ãå·Ô¬ 6</span> ãÖ¦¨áé·å ÆÖÔª·¬çá ¤·ÖÔÔñ½ ª ½Ð.<br /><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 5: ¸ãØÖÐíóÖë Ô·¨ ConfigReader::Simple.</span><br /><div class="code"><pre>1 #!/usr/bin/perl -w 2 use strict; 3 4 use ConfigReader::Simple; 5 use LWP::Simple; 6 use Text::Template qw(fill_in_file); 7 use XML::RSS; 8 9 my $config = ConfigReader::Simple-&gt;new( './rss.config' ); 10 11 my $base = $config-&gt;base; 12 my $template = $config-&gt;template; 13 my $extension = $config-&gt;extension; 14 15 my @files = split /\s+/, $config-&gt;files; 16 17 foreach my $url ( @files ) 18 { 19 my $file = $url; 20 21 $file =~ s|.*/||; 22 23 my $result = open my $fh, &quot;&gt; $base/$file.$extension&quot;; 24 25 unless( $result ) 26 { 27 warn &quot;Could not open [$file] for writing! $!&quot;; 28 next; 29 } 30 31 my $rss = XML::RSS-&gt;new(); 32 my $data = get( $url ); 33 $rss-&gt;parse( $data ); 34 35 print $fh fill_in_file( $template, HASH =&gt; $rss ); 36 close $fh; 37 }</pre></div><br /><span style="font-style:italic">Ñ·ãå·Ô¬ 6: « ½Ð ÆÖÔª·¬çá ¤··.</span><br /><div class="code"><pre>1 base . 2 template rss-html.tmpl 3 files http://use.perl.org/useperl.rss 4 extension html</pre></div><br /><br /><span style="font-weight:bold">4. ô ÆÐœû¨Ô·¨.</span><br /><br />à ÒÖ¬ç çÒ¨Ôíõ·åí á óÒ¨á ÒÖ·µ ØáÖ¬á ÒÒ, Ö妨ÐÞÞ ÆÖ¦ Öå ÐÖ¬·Æ· Øᨦãå ëÐ¨Ô·Þ · ÆÖÔª·¬çá ¤·ÖÔÔÖ½ ·ÔªÖáÒ ¤··. øåÖ á ó¦¨Ð¨Ô·¨ ¦¨Ð ¨å ØáÖ¬á ÒÒç ¢ÖШ¨ ¬·¢ÆÖ½ · ØáÖãåÖ½ ë  ¦ Øå ¤·· Æ ÔÖëñÒ ÖÆáçé¨Ô·ÞÒ. ö ¢ÐÖÔñ ØÖóëÖÐÞœå ·óÒ¨ÔÞåí ëñëÖ¦,   ÆÖÔª·¬çá ¤·ÖÔÔñ¨ ª ½Ðñ çØá ëÐÞåí á ¢ÖåÖ½ ØáÖ¬á ÒÒñ ¢¨ó ·óÒ¨Ô¨Ô·Þ ÆÖ¦ . Text::Template · ConfigReader::Simple ¦¨Ð œå ÷åÖ Ô ãåÖÐíÆÖ ØáÖãåñÒ, Ô ãÆÖÐíÆÖ ëÖóÒÖéÔÖ.<br /><br /><span style="font-weight:bold">5. äãñÐÆ·</span><br /><br />ì㨠ÒÖ¦çз, çØÖÒ·Ô ¨Òñ¨ ë ÷åÖ½ ãå åí¨, ÒÖéÔÖ Ô ½å· Ô  Comprehensive Perl Archive Network (CPAN) - <a target="_blank" href="http://search.cpan.org">http://search.cpan.org</a><br /><br /><span style="font-weight:bold">6. ×¢  ëåÖá¨.</span><br /><br />£á ½ Ô ¦¨ «Ö½ (brian d foy) - ·ó¦ å¨Ðí <span style="font-style:italic">The Perl Review</span>.<br /><br /><span style="font-weight:bold">Ýá·Ò¨û Ô·Þ.</span><br /><br /><span style="font-weight:bold"><sup>1</sup></span> &quot;Simple RSS with Perl&quot; by brian d foy, The Perl Review v0 i5, November 2002, <a target="_blank" href="http://www.theperlreview.com">http://www.ThePerlReview.com</a><br /><br /><span style="font-weight:bold"><sup>2</sup></span> <a target="_blank" href="http://search.cpan.org">http://search.cpan.org</a><br /><br /><a target="_blank" href="http://www.theperlreview.com/Articles/v0i7/config.pdf">Öá·¬·Ô Ð ãå åí· Ô  Perl Review (PDF)</a> ÑÖ¢ ÔÖë ¸¬Öáí <authors@template-toolkit.ru> http://forum.template-toolkit.ru/view_topic/topic_id-53.html §á笷¨ å¨Òñ, ãëÞó ÔÔñ¨ ã õ ¢ÐÖÔ Ò· · Perl http://forum.template-toolkit.ru/view_topic/topic_id-53.html?rss