Home arrow Perl Programming arrow Build a Perl RSS Aggregator with Templating Tools

Build a Perl RSS Aggregator with Templating Tools

In this third part of a five-part series on templating tools, you'll learn how to write a simple RSS aggregator, and more. It is excerpted from chapter three of the book Advanced Perl Programming, Second Edition, written by Simon Cozens (O'Reilly; ISBN: 0596004567). Copyright 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. Build a Perl RSS Aggregator with Templating Tools
  2. RSS Aggregation
  3. HTML::Mason
  4. Basic Dynamism
By: O'Reilly Media
Rating: starstarstarstarstar / 2
August 21, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Loops

If we're going to get anywhere with our RSS example, we'll need to loop over a series of items--the stories in our newsreel. Thankfully, HTML::Template provides the <TMPL_LOOP> pseudotag for treating a variable as an array. For instance, the following code:

  <ul>
  <TMPL_LOOP NAME=STORIES>
     
<li> From <TMPL_VAR NAME=FEED_NAME>: <TMPL_VAR NAME=STORY_NAME> </li>
  </TMPL_LOOP>
  </ul>

when provided the appropriate data structure, loops over the items in the STORIES array reference and produces output like so:

  <ul>

      <li>
From Slashdot: NASA Finds Monkeys on Mars </li>
 
      <li>
From use.perl: Perl 6 Release Predicted for 2013 </li>

  </ul>

The trick is that the array reference needs to contain an array of hashes, and each hash provides the appropriate variable names:

  $template->param(STORIES => [
  
{ FEED_NAME => "Slashdot", STORY_NAME => "NASA Finds Monkeys on Mars" },
  
{ FEED_NAME => "use.perl", STORY_NAME => "Perl 6 Release Predicted for 2013" }
  ]);



 
 
>>> More Perl Programming Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: