<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>All Blogs - Author(s): Rob Earl</title>
		<link>http://blogs.lessthandot.com/index.php/All/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/All/?tempskin=_rss2" />
		<description>LessThanDot A Technical Community for IT Professionals</description>
		<language>en-US</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>Adding Stackoverflow user feed to your homepage</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/adding-stackoverflow-user-feed-on</link>
			<pubDate>Sun, 16 Dec 2012 16:48:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Server Programming</category>
<category domain="alt">Perl</category>			<guid isPermaLink="false">1972@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Following on from a comment on a &lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml&quot;&gt;previous post&lt;/a&gt;, this post will demonstrate how to use XML::Feed and Template::Toolkit to format your recent Stackoverflow activity, suitable for including on your own web page. Aptly, this was aided by a &lt;a href=&quot;http://stackoverflow.com/q/13897382/1691146&quot;&gt;stackoverflow question&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;This time we can use XML::Feed both to get and parse the feed:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb50224&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; XML::&lt;span style=&quot;color: #006600;&quot;&gt;Feed&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; = XML::&lt;span style=&quot;color: #006600;&quot;&gt;Feed&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;URI-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;http://stackoverflow.com/feeds/user/1691146&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb74936&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We need to adapt the template to account for XML::Feed&#039;s differences: &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb15426&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt; = &amp;lt;&amp;lt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;TEMPLATE&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% feed.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Activity:&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% FOREACH item = feed.items %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.issued.dmy %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.issued.hms %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;\t&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% END %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;TEMPLATE&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb69054&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the template toolkit invocation:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb40599&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;feed&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb37146&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Full example:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb68360&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; warnings;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; XML::&lt;span style=&quot;color: #006600;&quot;&gt;Feed&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Template;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$stackoverflow_id&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;1691146&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$stackoverflow_url&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://stackoverflow.com/feeds/user/$stackoverflow_id&amp;quot;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt; = &amp;lt;&amp;lt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;TEMPLATE&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% feed.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Activity:&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% FOREACH item = feed.items %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.issued.dmy %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.issued.hms %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;\t&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% END %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;TEMPLATE&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt; = Template-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;STRICT&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Failed to load template: $Template::ERROR&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; = XML::&lt;span style=&quot;color: #006600;&quot;&gt;Feed&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;URI-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$stackoverflow_url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;feed&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb69244&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is still a really simple script with added support for Atom feeds.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/adding-stackoverflow-user-feed-on&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Following on from a comment on a <a href="http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml">previous post</a>, this post will demonstrate how to use XML::Feed and Template::Toolkit to format your recent Stackoverflow activity, suitable for including on your own web page. Aptly, this was aided by a <a href="http://stackoverflow.com/q/13897382/1691146">stackoverflow question</a>!</p>

<p>This time we can use XML::Feed both to get and parse the feed:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb76118'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb76118','cb90422'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb76118" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> XML::<span style="color: #006600;">Feed</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed</span> = XML::<span style="color: #006600;">Feed</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>URI-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://stackoverflow.com/feeds/user/1691146'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb90422" style="display: none; color: red;"></div></div></div>

<p>We need to adapt the template to account for XML::Feed's differences: </p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb42267'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb42267','cb83317'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb42267" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$template</span> = &lt;&lt;<span style="color: #ff0000;">&quot;TEMPLATE&quot;</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% feed.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Activity:</li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% FOREACH item = feed.items %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% item.issued.dmy %<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>% item.issued.hms %<span style="color: #66cc66;">&#93;</span>\t<span style="color: #66cc66;">&#91;</span>% item.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% END %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2">TEMPLATE</li></ol></div><div id="cb83317" style="display: none; color: red;"></div></div></div>

<p>And the template toolkit invocation:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb54274'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb54274','cb76292'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb54274" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">process</span><span style="color: #66cc66;">&#40;</span> \<span style="color: #0000ff;">$template</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'feed'</span> =&gt; <span style="color: #0000ff;">$feed</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb76292" style="display: none; color: red;"></div></div></div>

<p>Full example:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb88831'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb88831','cb59086'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb88831" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> warnings;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> XML::<span style="color: #006600;">Feed</span>;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Template;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stackoverflow_id</span> = <span style="color: #cc66cc;">1691146</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stackoverflow_url</span> = <span style="color: #ff0000;">&quot;http://stackoverflow.com/feeds/user/$stackoverflow_id&quot;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$template</span> = &lt;&lt;<span style="color: #ff0000;">&quot;TEMPLATE&quot;</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% feed.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">Activity:</li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% FOREACH item = feed.items %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% item.issued.dmy %<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>% item.issued.hms %<span style="color: #66cc66;">&#93;</span>\t<span style="color: #66cc66;">&#91;</span>% item.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% END %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1">TEMPLATE</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tt</span> = Template-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'STRICT'</span> =&gt; <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Failed to load template: $Template::ERROR<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed</span> = XML::<span style="color: #006600;">Feed</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>URI-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$stackoverflow_url</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">process</span><span style="color: #66cc66;">&#40;</span> \<span style="color: #0000ff;">$template</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'feed'</span> =&gt; <span style="color: #0000ff;">$feed</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb59086" style="display: none; color: red;"></div></div></div>

<p>This is still a really simple script with added support for Atom feeds.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/adding-stackoverflow-user-feed-on">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/adding-stackoverflow-user-feed-on#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1972</wfw:commentRss>
		</item>
				<item>
			<title>Create HTML from output of Perl::Critic</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/perl/create-html-from-output-of</link>
			<pubDate>Sat, 22 Sep 2012 07:46:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Perl</category>			<guid isPermaLink="false">1841@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;&lt;a href=&quot;http://search.cpan.org/~thaljef/Perl-Critic-1.118/lib/Perl/Critic.pm&quot;&gt;Perl::Critic&lt;/a&gt; is great. If you haven&#039;t tried it, you should. It can help you improve the quality of your code no end.&lt;/p&gt;

&lt;p&gt;I wrote this script to make it easier to view the feedback in the context of the code itself. When run in a directory containing Perl code it&#039;ll create a critic_html directory containing index.html summarizing the results:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic-html-index.jpg&quot; alt=&quot;critic_html/index.html&quot; title=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Clicking through to any of the files will give you all the violations found by Perl::Critic, inline with the code:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic-html-code.jpg&quot; alt=&quot;&quot; title=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In addition to Perl::Critic, the script uses Template::Toolkit to format the output. The code below and templates can be found in the attached &lt;a href=&quot;http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic_html.zip&quot;&gt;critic_html.zip&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb8441&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; warnings;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Perl::&lt;span style=&quot;color: #006600;&quot;&gt;Critic&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Perl::&lt;span style=&quot;color: #006600;&quot;&gt;Critic&lt;/span&gt;::&lt;span style=&quot;color: #006600;&quot;&gt;Utils&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Template;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Cwd &lt;a href=&quot;http://perldoc.perl.org/functions/qw.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;qw&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;abs_path&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; File::&lt;span style=&quot;color: #006600;&quot;&gt;Basename&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; English &lt;a href=&quot;http://perldoc.perl.org/functions/qw.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;qw&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;-no_match_vars&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; constant SEVERITY &amp;nbsp;=&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Include all violations.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; constant SKIP_GOOD =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Skip files with no violations?&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/mkdir.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mkdir&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;critic_html&#039;&lt;/span&gt;;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/mkdir.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mkdir&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;critic_html/src&#039;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; autodie;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Analyse all perl files below the current directory.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@files&lt;/span&gt; = Perl::&lt;span style=&quot;color: #006600;&quot;&gt;Critic&lt;/span&gt;::&lt;span style=&quot;color: #006600;&quot;&gt;Utils&lt;/span&gt;::&lt;span style=&quot;color: #006600;&quot;&gt;all_perl_files&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/q.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;q&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@summary&lt;/span&gt; = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Store statistics on each file processed.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;@files&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Create a new Critic for per file statistics.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$critic&lt;/span&gt; = Perl::&lt;span style=&quot;color: #006600;&quot;&gt;Critic&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;-severity&#039;&lt;/span&gt; =&amp;gt; SEVERITY &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$file_safe&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$file&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$file_safe&lt;/span&gt; =~ &lt;a href=&quot;http://perldoc.perl.org/functions/s.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;s&lt;/span&gt;&lt;/a&gt;/&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;\W&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;/_/g;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@violations&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$critic&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;critique&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;next&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;span style=&quot;color: #0000ff;&quot;&gt;@violations&lt;/span&gt; &amp;amp;&amp;amp; SKIP_GOOD&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/push.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;push&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@summary&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;filename&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$file&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;link&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;src/$file_safe.html&amp;quot;&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;stats&#039;&lt;/span&gt; &amp;nbsp; &amp;nbsp;=&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$critic&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;statistics&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/open.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;open&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$FH&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&amp;lt;&#039;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$file&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@lines&lt;/span&gt; = &amp;lt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$FH&lt;/span&gt;&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/close.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;close&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$FH&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Attach all violations to the line they were found on.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@violations_by_line&lt;/span&gt; = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$line_number&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$line&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;@lines&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Get all the violations for the current line.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@line_violations&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/grep.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;grep&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$_&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;line_number&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; == &lt;span style=&quot;color: #0000ff;&quot;&gt;$line_number&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@violations&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/push.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;push&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;@violations_by_line&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;number&#039;&lt;/span&gt; &amp;nbsp;=&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$line_number&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;content&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$line&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;violations&#039;&lt;/span&gt; =&amp;gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;@line_violations&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$line_number&lt;/span&gt;++;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write_html&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;critic_html/src/$file_safe.html&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;codefile&#039;&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;title&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Critic Analysis of $file&amp;quot;&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lines&#039;&lt;/span&gt; =&amp;gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;@violations_by_line&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;write_html&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;critic_html/index.html&#039;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;index&#039;&lt;/span&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;title&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Perl::Critic::HTML Summary&#039;&lt;/span&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;files&#039;&lt;/span&gt; =&amp;gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;@summary&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; write_html &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$filename&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;@_&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Include templates from the install directory.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt; = Template-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;INCLUDE_PATH&#039;&lt;/span&gt; =&amp;gt; dirname&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;abs_path&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$PROGRAM_NAME&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/templates&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/print.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Writing $filename&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/open.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;open&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$FILE&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&amp;gt;&#039;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$filename&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$data&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$FILE&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/close.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;close&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$FILE&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb96272&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/perl/create-html-from-output-of&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p><a href="http://search.cpan.org/~thaljef/Perl-Critic-1.118/lib/Perl/Critic.pm">Perl::Critic</a> is great. If you haven't tried it, you should. It can help you improve the quality of your code no end.</p>

<p>I wrote this script to make it easier to view the feedback in the context of the code itself. When run in a directory containing Perl code it'll create a critic_html directory containing index.html summarizing the results:</p>

<p><img src="http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic-html-index.jpg" alt="critic_html/index.html" title="" /></p>

<p>Clicking through to any of the files will give you all the violations found by Perl::Critic, inline with the code:</p>

<p><img src="http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic-html-code.jpg" alt="" title="" /></p>

<p>In addition to Perl::Critic, the script uses Template::Toolkit to format the output. The code below and templates can be found in the attached <a href="http://blogs.lessthandot.com/media/blogs/WebDev/CriticHtml/critic_html.zip">critic_html.zip</a></p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb39052'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb39052','cb20844'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb39052" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> warnings;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> Perl::<span style="color: #006600;">Critic</span>;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Perl::<span style="color: #006600;">Critic</span>::<span style="color: #006600;">Utils</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Template;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> Cwd <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>abs_path<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> File::<span style="color: #006600;">Basename</span>;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> English <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>-no_match_vars<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> constant SEVERITY &nbsp;=&gt; <span style="color: #cc66cc;">1</span>; <span style="color: #808080; font-style: italic;"># Include all violations.</span></li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> constant SKIP_GOOD =&gt; <span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;"># Skip files with no violations?</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><a href="http://perldoc.perl.org/functions/mkdir.html"><span style="color: #000066;">mkdir</span></a> <span style="color: #ff0000;">'critic_html'</span>;</li><li style="" class="li2"><a href="http://perldoc.perl.org/functions/mkdir.html"><span style="color: #000066;">mkdir</span></a> <span style="color: #ff0000;">'critic_html/src'</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> autodie;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #808080; font-style: italic;"># Analyse all perl files below the current directory.</span></li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@files</span> = Perl::<span style="color: #006600;">Critic</span>::<span style="color: #006600;">Utils</span>::<span style="color: #006600;">all_perl_files</span><span style="color: #66cc66;">&#40;</span><a href="http://perldoc.perl.org/functions/q.html"><span style="color: #000066;">q</span></a><span style="color: #66cc66;">&#123;</span>.<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@summary</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;"># Store statistics on each file processed.</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@files</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Create a new Critic for per file statistics.</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$critic</span> = Perl::<span style="color: #006600;">Critic</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'-severity'</span> =&gt; SEVERITY <span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file_safe</span> = <span style="color: #0000ff;">$file</span>;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0000ff;">$file_safe</span> =~ <a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>/<span style="color: #66cc66;">&#91;</span>\W<span style="color: #66cc66;">&#93;</span>/_/g;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@violations</span> = <span style="color: #0000ff;">$critic</span>-&gt;<span style="color: #006600;">critique</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">@violations</span> &amp;&amp; SKIP_GOOD<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@summary</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'filename'</span> =&gt; <span style="color: #0000ff;">$file</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'link'</span> &nbsp; &nbsp; =&gt; <span style="color: #ff0000;">&quot;src/$file_safe.html&quot;</span>,</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'stats'</span> &nbsp; &nbsp;=&gt; <span style="color: #0000ff;">$critic</span>-&gt;<span style="color: #006600;">statistics</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$FH</span>, <span style="color: #ff0000;">'&lt;'</span>, <span style="color: #0000ff;">$file</span>;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@lines</span> = &lt;<span style="color: #0000ff;">$FH</span>&gt;;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> <span style="color: #0000ff;">$FH</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Attach all violations to the line they were found on.</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@violations_by_line</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line_number</span> = <span style="color: #cc66cc;">1</span>;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@lines</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Get all the violations for the current line.</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@line_violations</span> = <a href="http://perldoc.perl.org/functions/grep.html"><span style="color: #000066;">grep</span></a> <span style="color: #66cc66;">&#123;</span> <span style="color: #0000ff;">$_</span>-&gt;<span style="color: #006600;">line_number</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #0000ff;">$line_number</span><span style="color: #66cc66;">&#125;</span> <span style="color: #0000ff;">@violations</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@violations_by_line</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'number'</span> &nbsp;=&gt; <span style="color: #0000ff;">$line_number</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'content'</span> =&gt; <span style="color: #0000ff;">$line</span>,</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'violations'</span> =&gt; \<span style="color: #0000ff;">@line_violations</span> <span style="color: #66cc66;">&#125;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$line_number</span>++;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; write_html<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;critic_html/src/$file_safe.html&quot;</span>, <span style="color: #ff0000;">'codefile'</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'title'</span> =&gt; <span style="color: #ff0000;">&quot;Critic Analysis of $file&quot;</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'lines'</span> =&gt; \<span style="color: #0000ff;">@violations_by_line</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">write_html<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'critic_html/index.html'</span>, <span style="color: #ff0000;">'index'</span>, <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'title'</span> =&gt; <span style="color: #ff0000;">'Perl::Critic::HTML Summary'</span>,</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'files'</span> =&gt; \<span style="color: #0000ff;">@summary</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> write_html <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span>, <span style="color: #0000ff;">$template</span>, <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #0000ff;">@_</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Include templates from the install directory.</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tt</span> = Template-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'INCLUDE_PATH'</span> =&gt; dirname<span style="color: #66cc66;">&#40;</span>abs_path<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$PROGRAM_NAME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'/templates'</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;Writing $filename<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</li><li style="" class="li2">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$FILE</span>, <span style="color: #ff0000;">'&gt;'</span>, <span style="color: #0000ff;">$filename</span>;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">process</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$template</span>, <span style="color: #0000ff;">$data</span>, <span style="color: #0000ff;">$FILE</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> <span style="color: #0000ff;">$FILE</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a>;</li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb20844" style="display: none; color: red;"></div></div></div><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/perl/create-html-from-output-of">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/perl/create-html-from-output-of#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1841</wfw:commentRss>
		</item>
				<item>
			<title>Taming RSS Feeds with XML::RSS and Template::Toolkit</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml</link>
			<pubDate>Fri, 14 Sep 2012 11:01:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="alt">Server Programming</category>
<category domain="main">Perl</category>			<guid isPermaLink="false">1828@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;This is a remarkably simple trick which I&#039;ve found very handy. With a few lines of Perl you can take any RSS feed and format it to your liking.&lt;/p&gt;
&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Get the Feed&lt;/h1&gt;
&lt;p&gt;You can do this using &lt;a href=&quot;http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/Simple.pm&quot;&gt;LWP::Simple&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb67158&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; LWP::&lt;span style=&quot;color: #006600;&quot;&gt;Simple&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed_url&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;http://feeds.bbci.co.uk/news/rss.xml&#039;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; = get&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$feed_url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Failed to fetch feed.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb85301&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Process the Raw Result&lt;/h1&gt;
&lt;p&gt;Using &lt;a href=&quot;http://search.cpan.org/~kellan/XML-RSS-1.05/lib/RSS.pm&quot;&gt;XML::RSS&lt;/a&gt;, convert the raw feed into a more manageable hash.&lt;/p&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb67153&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; XML::&lt;span style=&quot;color: #006600;&quot;&gt;RSS&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt; = XML::&lt;span style=&quot;color: #006600;&quot;&gt;RSS&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb20595&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Format to Your Liking&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;http://template-toolkit.org/&quot;&gt;Template::Toolkit&lt;/a&gt; can take in a &lt;a href=&quot;http://template-toolkit.org/docs/manual/Syntax.html&quot;&gt;template&lt;/a&gt; and a hash reference of values to substitute into the template.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb82669&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Define a template&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt; = &amp;lt;&amp;lt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;TEMPLATE&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% channel.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Headlines:&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% FOREACH item = items %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.pubDate %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;\t&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% END %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;TEMPLATE&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb13650&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This simple template will take the BBC news feed from above and print out a list of headlines with publication dates.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb96086&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt; = Template-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Failed to load template: $Template::ERROR&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Combine the template with the processed RSS feed.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb80139&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1&gt;&lt;/h1&gt;
&lt;h1&gt;Putting it All Together&lt;/h1&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb86718&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; warnings;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; XML::&lt;span style=&quot;color: #006600;&quot;&gt;RSS&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; LWP::&lt;span style=&quot;color: #006600;&quot;&gt;Simple&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Template;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;##################&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Configuration:&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;##################&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed_url&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;http://feeds.bbci.co.uk/news/rss.xml&#039;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt; = &amp;lt;&amp;lt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;TEMPLATE&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% channel.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Headlines:&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% FOREACH item = items %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.pubDate %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;\t&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% item.title %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;% END %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;TEMPLATE&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;##################&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;##################&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt; = Template-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Failed to load template: $Template::ERROR&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt; = get&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$feed_url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Failed to fetch feed.&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt; = XML::&lt;span style=&quot;color: #006600;&quot;&gt;RSS&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$feed&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; \&lt;span style=&quot;color: #0000ff;&quot;&gt;$template&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$rss&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;or&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/die.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tt&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb92546&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;bash&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;bash&quot; id=&quot;cb64089&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;rob@arrakis:~/public_html/rss-reader$ &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;perl&lt;/span&gt; rss-reader.pl &lt;br /&gt;BBC News - Home&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Headlines:&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Fri, &lt;span style=&quot;color: #000000;&quot;&gt;14&lt;/span&gt; Sep &lt;span style=&quot;color: #000000;&quot;&gt;2012&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;12&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;15&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;22&lt;/span&gt; GMT&amp;nbsp; &amp;nbsp;Kate privacy invasion &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;grotesque&#039;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Fri, &lt;span style=&quot;color: #000000;&quot;&gt;14&lt;/span&gt; Sep &lt;span style=&quot;color: #000000;&quot;&gt;2012&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;11&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;49&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;10&lt;/span&gt; GMT&amp;nbsp; &amp;nbsp;US missions on film protest alert&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Fri, &lt;span style=&quot;color: #000000;&quot;&gt;14&lt;/span&gt; Sep &lt;span style=&quot;color: #000000;&quot;&gt;2012&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;12&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;25&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;25&lt;/span&gt; GMT&amp;nbsp; &amp;nbsp;Alps attack girl returning to UK&lt;br /&gt;&amp;nbsp;&lt;br /&gt;Fri, &lt;span style=&quot;color: #000000;&quot;&gt;14&lt;/span&gt; Sep &lt;span style=&quot;color: #000000;&quot;&gt;2012&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;10&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;17&lt;/span&gt;:&lt;span style=&quot;color: #000000;&quot;&gt;03&lt;/span&gt; GMT&amp;nbsp; &amp;nbsp;Woman is held after car body &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;find&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb30510&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this example the RSS feed and template are defined in code but they can just as easily be defined in files or a database allowing for changes/additions without deploying new code.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>This is a remarkably simple trick which I've found very handy. With a few lines of Perl you can take any RSS feed and format it to your liking.</p>
<h1></h1>
<h1>Get the Feed</h1>
<p>You can do this using <a href="http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/Simple.pm">LWP::Simple</a>:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb43728'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb43728','cb14465'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb43728" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> LWP::<span style="color: #006600;">Simple</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed_url</span> = <span style="color: #ff0000;">'http://feeds.bbci.co.uk/news/rss.xml'</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed</span> = get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$feed_url</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Failed to fetch feed.&quot;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb14465" style="display: none; color: red;"></div></div></div>

<h1></h1>
<h1>Process the Raw Result</h1>
<p>Using <a href="http://search.cpan.org/~kellan/XML-RSS-1.05/lib/RSS.pm">XML::RSS</a>, convert the raw feed into a more manageable hash.</p>
<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb76416'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb76416','cb30836'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb76416" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> XML::<span style="color: #006600;">RSS</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rss</span> = XML::<span style="color: #006600;">RSS</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000ff;">$rss</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$feed</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb30836" style="display: none; color: red;"></div></div></div>

<h1></h1>
<h1>Format to Your Liking</h1>
<p><a href="http://template-toolkit.org/">Template::Toolkit</a> can take in a <a href="http://template-toolkit.org/docs/manual/Syntax.html">template</a> and a hash reference of values to substitute into the template.</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb6693'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb6693','cb29038'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb6693" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;"># Define a template</span></li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$template</span> = &lt;&lt;<span style="color: #ff0000;">&quot;TEMPLATE&quot;</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% channel.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">Headlines:</li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% FOREACH item = items %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% item.pubDate %<span style="color: #66cc66;">&#93;</span>\t<span style="color: #66cc66;">&#91;</span>% item.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% END %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1">TEMPLATE</li></ol></div><div id="cb29038" style="display: none; color: red;"></div></div></div>

<p>This simple template will take the BBC news feed from above and print out a list of headlines with publication dates.</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb30978'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb30978','cb45167'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb30978" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tt</span> = Template-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Failed to load template: $Template::ERROR<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #808080; font-style: italic;"># Combine the template with the processed RSS feed.</span></li><li style="" class="li1"><span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">process</span> <span style="color: #66cc66;">&#40;</span> \<span style="color: #0000ff;">$template</span>, <span style="color: #0000ff;">$rss</span> <span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb45167" style="display: none; color: red;"></div></div></div>

<h1></h1>
<h1>Putting it All Together</h1>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb56648'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb56648','cb95508'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb56648" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> warnings;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> XML::<span style="color: #006600;">RSS</span>;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> LWP::<span style="color: #006600;">Simple</span>;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Template;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #808080; font-style: italic;">##################</span></li><li style="" class="li2"><span style="color: #808080; font-style: italic;"># Configuration:</span></li><li style="" class="li1"><span style="color: #808080; font-style: italic;">#</span></li><li style="" class="li2"><span style="color: #808080; font-style: italic;">##################</span></li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed_url</span> = <span style="color: #ff0000;">'http://feeds.bbci.co.uk/news/rss.xml'</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$template</span> = &lt;&lt;<span style="color: #ff0000;">&quot;TEMPLATE&quot;</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% channel.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">Headlines:</li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% FOREACH item = items %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#91;</span>% item.pubDate %<span style="color: #66cc66;">&#93;</span>\t<span style="color: #66cc66;">&#91;</span>% item.title %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#91;</span>% END %<span style="color: #66cc66;">&#93;</span></li><li style="" class="li1">TEMPLATE</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #808080; font-style: italic;">##################</span></li><li style="" class="li2"><span style="color: #808080; font-style: italic;">##################</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tt</span> = Template-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Failed to load template: $Template::ERROR<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$feed</span> = get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$feed_url</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Failed to fetch feed.'</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rss</span> = XML::<span style="color: #006600;">RSS</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1"><span style="color: #0000ff;">$rss</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$feed</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">process</span> <span style="color: #66cc66;">&#40;</span> \<span style="color: #0000ff;">$template</span>, <span style="color: #0000ff;">$rss</span> <span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #0000ff;">$tt</span>-&gt;<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb95508" style="display: none; color: red;"></div></div></div>

<div class="codebox"><div class="codeheader"><span>bash</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb7830'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb7830','cb6286'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="bash" id="cb7830" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">rob@arrakis:~/public_html/rss-reader$ <span style="color: #c20cb9; font-weight: bold;">perl</span> rss-reader.pl </li><li style="" class="li2">BBC News - Home</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Headlines:</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Fri, <span style="color: #000000;">14</span> Sep <span style="color: #000000;">2012</span> <span style="color: #000000;">12</span>:<span style="color: #000000;">15</span>:<span style="color: #000000;">22</span> GMT&nbsp; &nbsp;Kate privacy invasion <span style="color: #ff0000;">'grotesque'</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Fri, <span style="color: #000000;">14</span> Sep <span style="color: #000000;">2012</span> <span style="color: #000000;">11</span>:<span style="color: #000000;">49</span>:<span style="color: #000000;">10</span> GMT&nbsp; &nbsp;US missions on film protest alert</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Fri, <span style="color: #000000;">14</span> Sep <span style="color: #000000;">2012</span> <span style="color: #000000;">12</span>:<span style="color: #000000;">25</span>:<span style="color: #000000;">25</span> GMT&nbsp; &nbsp;Alps attack girl returning to UK</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Fri, <span style="color: #000000;">14</span> Sep <span style="color: #000000;">2012</span> <span style="color: #000000;">10</span>:<span style="color: #000000;">17</span>:<span style="color: #000000;">03</span> GMT&nbsp; &nbsp;Woman is held after car body <span style="color: #c20cb9; font-weight: bold;">find</span></li></ol></div><div id="cb6286" style="display: none; color: red;"></div></div></div>

<p>In this example the RSS feed and template are defined in code but they can just as easily be defined in files or a database allowing for changes/additions without deploying new code.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/perl/taming-rss-feeds-with-xml#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1828</wfw:commentRss>
		</item>
				<item>
			<title>Using a Perl Singleton to Share Values Between Objects</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/using-a-perl-singleton</link>
			<pubDate>Wed, 12 Sep 2012 14:54:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Server Programming</category>
<category domain="alt">Perl</category>			<guid isPermaLink="false">1825@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;It&#039;s been quite a while since I last posted here. Since my last entry I got a new job,  got married, went on honeymoon (got back yesterday!) and spent quite a lot of time maintaining legacy Perl code.&lt;/p&gt;

&lt;p&gt;One thing I see a lot is sharing objects by passing them to the constructor of a new object. This is fine until you&#039;re dealing with complicated sets of objects within objects. &lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb65715&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Read some variables out of a configuration file.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = get_config&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$config_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Create a new object which contains an object which uses some values from the config.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object&lt;/span&gt; = MyObject-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$object&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;do_something&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/package.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;package&lt;/span&gt;&lt;/a&gt; MyObject;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Store the config incase we create any objects which need it.&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt; = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;config&#039;&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/bless.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;bless&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; do_something &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object2&lt;/span&gt; = MyObject2-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;config&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object2&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;do_something_else&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb24964&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;MyObject is now holding a reference to the config object which it doesn&#039;t need directly. This will only get worse if MyObject2 needs another object which requires the config object, etc.&lt;/p&gt;

&lt;p&gt;Instead we could use a singleton object:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb83938&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/package.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;package&lt;/span&gt;&lt;/a&gt; MyConfigObject;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Carp;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/undef.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;undef&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config_file&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; croak &lt;span style=&quot;color: #b1b100;&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config_file&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/bless.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;bless&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;parse_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$config_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb73693&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The example above changes to:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb81413&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Create a new object to hold the values from our config file.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = MyConfigObject-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$config_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Create a new object which contains an object which uses some values from the config.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object&lt;/span&gt; = MyObject-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$object&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;do_something&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/package.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;package&lt;/span&gt;&lt;/a&gt; MyObject;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/bless.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;bless&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; do_something &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object2&lt;/span&gt; = MyObject2-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$object2&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;do_something_else&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/package.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;package&lt;/span&gt;&lt;/a&gt; MyObject2;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Get the config object&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$config&lt;/span&gt; = MyConfigObject-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Do some stuff with it!&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb12643&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Whenever we need to use a value from the config file, we create a new MyConfigObject and get the instance we already created without having to reparse the config file or maintain complicated links through parent objects.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/using-a-perl-singleton&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>It's been quite a while since I last posted here. Since my last entry I got a new job,  got married, went on honeymoon (got back yesterday!) and spent quite a lot of time maintaining legacy Perl code.</p>

<p>One thing I see a lot is sharing objects by passing them to the constructor of a new object. This is fine until you're dealing with complicated sets of objects within objects. </p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb75524'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb75524','cb89039'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb75524" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #808080; font-style: italic;"># Read some variables out of a configuration file.</span></li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config</span> = get_config<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config_file</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #808080; font-style: italic;"># Create a new object which contains an object which uses some values from the config.</span></li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$object</span> = MyObject-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">do_something</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> MyObject;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Store the config incase we create any objects which need it.</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> = <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">'config'</span> =&gt; <span style="color: #0000ff;">$config</span> <span style="color: #66cc66;">&#125;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <a href="http://perldoc.perl.org/functions/bless.html"><span style="color: #000066;">bless</span></a> <span style="color: #0000ff;">$self</span>, <span style="color: #0000ff;">$class</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> do_something <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$object2</span> = MyObject2-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$self</span>-&gt;<span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">'config'</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$object2</span>-&gt;<span style="color: #006600;">do_something_else</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb89039" style="display: none; color: red;"></div></div></div>

<p>MyObject is now holding a reference to the config object which it doesn't need directly. This will only get worse if MyObject2 needs another object which requires the config object, etc.</p>

<p>Instead we could use a singleton object:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb90837'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb90837','cb31516'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb90837" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> MyConfigObject;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> Carp;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config</span> = <a href="http://perldoc.perl.org/functions/undef.html"><span style="color: #000066;">undef</span></a>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$config</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config_file</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; croak <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$config_file</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$config</span> = <a href="http://perldoc.perl.org/functions/bless.html"><span style="color: #000066;">bless</span></a> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #0000ff;">$class</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$config</span>-&gt;<span style="color: #006600;">parse_file</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config_file</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$config</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb31516" style="display: none; color: red;"></div></div></div>

<p>The example above changes to:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb81379'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb81379','cb20730'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb81379" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #808080; font-style: italic;"># Create a new object to hold the values from our config file.</span></li><li style="" class="li2"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config</span> = MyConfigObject-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config_file</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #808080; font-style: italic;"># Create a new object which contains an object which uses some values from the config.</span></li><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$object</span> = MyObject-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">do_something</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> MyObject;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <a href="http://perldoc.perl.org/functions/bless.html"><span style="color: #000066;">bless</span></a> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #0000ff;">$class</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> do_something <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$object2</span> = MyObject2-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$object2</span>-&gt;<span style="color: #006600;">do_something_else</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> MyObject2;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Get the config object</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$config</span> = MyConfigObject-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Do some stuff with it!</span></li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb20730" style="display: none; color: red;"></div></div></div>

<p>Whenever we need to use a value from the config file, we create a new MyConfigObject and get the instance we already created without having to reparse the config file or maintain complicated links through parent objects.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/using-a-perl-singleton">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/using-a-perl-singleton#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1825</wfw:commentRss>
		</item>
				<item>
			<title>Manipulating Test Data with Sed</title>
			<link>http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/manipulating-test-data-with-sed</link>
			<pubDate>Sun, 22 May 2011 12:41:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Linux</category>			<guid isPermaLink="false">1269@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Following on from my &lt;a href=&quot;http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed&quot;&gt;previous blog about sed&lt;/a&gt;, this blog will detail how I use sed most often: manipulating test data when running demonstrations of new features. Let&#039;s say we&#039;ve developed a web service which creates users from the following XML document:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;xml&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;xml&quot; id=&quot;cb73396&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;user&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;username&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;USERNAME&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/username&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;password&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;PASSWORD&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/password&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/user&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb13250&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We might want to demonstrate this web service using a number of combinations of usernames and passwords, for instance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;robearl/password&lt;/li&gt;
&lt;li&gt;rob_earl/pass_word&lt;/li&gt;
&lt;li&gt;rob&#039;earl/pass&#039;word&lt;/li&gt;
&lt;li&gt;rob-earl/pass-word&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To do these tests we might create four XML documents containing each username/password pair. Every different combination we wanted to demonstrate would require a new document.&lt;/p&gt;

&lt;p&gt;Instead, we can use sed. Create a single document like the one above and pass it through sed to replace the variables before passing it to the web service using curl:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;bash&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;bash&quot; id=&quot;cb29349&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;cat&lt;/span&gt; single_document.xml | &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;sed&lt;/span&gt; -e &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;s/USERNAME/robearl/&#039;&lt;/span&gt; -e &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;s/PASSWORD/password/&#039;&lt;/span&gt; | curl &amp;lt;options&amp;gt; -d @- &amp;lt;web service&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb28372&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using this technique, we avoid having to create lots of XML documents and it&#039;s obvious what data is being passed without having to open up each document during the demonstration.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/manipulating-test-data-with-sed&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Following on from my <a href="http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed">previous blog about sed</a>, this blog will detail how I use sed most often: manipulating test data when running demonstrations of new features. Let's say we've developed a web service which creates users from the following XML document:</p>

<div class="codebox"><div class="codeheader"><span>xml</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb72388'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb72388','cb86483'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="xml" id="cb72388" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;username<span style="font-weight: bold; color: black;">&gt;</span></span></span>USERNAME<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/username<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;password<span style="font-weight: bold; color: black;">&gt;</span></span></span>PASSWORD<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/password<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user<span style="font-weight: bold; color: black;">&gt;</span></span></span></li></ol></div><div id="cb86483" style="display: none; color: red;"></div></div></div>

<p>We might want to demonstrate this web service using a number of combinations of usernames and passwords, for instance:</p>

<ul>
<li>robearl/password</li>
<li>rob_earl/pass_word</li>
<li>rob'earl/pass'word</li>
<li>rob-earl/pass-word</li>
<li>etc.</li>
</ul>

<p>To do these tests we might create four XML documents containing each username/password pair. Every different combination we wanted to demonstrate would require a new document.</p>

<p>Instead, we can use sed. Create a single document like the one above and pass it through sed to replace the variables before passing it to the web service using curl:</p>

<div class="codebox"><div class="codeheader"><span>bash</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb78008'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb78008','cb62511'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="bash" id="cb78008" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #c20cb9; font-weight: bold;">cat</span> single_document.xml | <span style="color: #c20cb9; font-weight: bold;">sed</span> -e <span style="color: #ff0000;">'s/USERNAME/robearl/'</span> -e <span style="color: #ff0000;">'s/PASSWORD/password/'</span> | curl &lt;options&gt; -d @- &lt;web service&gt;</li></ol></div><div id="cb62511" style="display: none; color: red;"></div></div></div>

<p>Using this technique, we avoid having to create lots of XML documents and it's obvious what data is being passed without having to open up each document during the demonstration.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/manipulating-test-data-with-sed">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/manipulating-test-data-with-sed#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/SysAdmins/?tempskin=_rss2&#38;disp=comments&#38;p=1269</wfw:commentRss>
		</item>
				<item>
			<title>Ignoring SVN Directories at the Command Line</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/ignoring-svn-directories-at-the</link>
			<pubDate>Sat, 14 May 2011 13:20:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">General Purpose Languages</category>			<guid isPermaLink="false">1257@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;A colleague of mine told me this neat trick which I had to share:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;bash&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;bash&quot; id=&quot;cb86885&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;FIGNORE=.svn&amp;quot;&lt;/span&gt; &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;source&lt;/span&gt; ~/.bashrc&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb85419&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now when you&#039;re moving around subversion controlled directories with only one subdirectory, hitting tab won&#039;t try to autocomplete to &quot;.svn/&quot;.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/ignoring-svn-directories-at-the&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>A colleague of mine told me this neat trick which I had to share:</p>

<div class="codebox"><div class="codeheader"><span>bash</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb94474'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb94474','cb18960'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="bash" id="cb94474" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;FIGNORE=.svn&quot;</span> &gt;&gt; ~/.bashrc</li><li style="" class="li2"><span style="color: #7a0874; font-weight: bold;">source</span> ~/.bashrc</li></ol></div><div id="cb18960" style="display: none; color: red;"></div></div></div>

<p>Now when you're moving around subversion controlled directories with only one subdirectory, hitting tab won't try to autocomplete to ".svn/".</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/ignoring-svn-directories-at-the">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/ignoring-svn-directories-at-the#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1257</wfw:commentRss>
		</item>
				<item>
			<title>Bulk Editing With Sed</title>
			<link>http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed</link>
			<pubDate>Sat, 30 Apr 2011 17:51:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Linux</category>			<guid isPermaLink="false">1229@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;This week, after refactoring some XML based Java classes, I was left with ~50 XML documents (used for testing) with the wrong root element. After a few seconds pondering opening a text editor and find/replacing 50 times I had a better idea: &lt;a href=&quot;http://www.gnu.org/software/sed/manual/sed.html&quot;&gt;sed&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;sed can be used to perform regular expressions on each line of a file (or files). To solve the problem all it took was:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb95181&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;sed -i s/oldroot/newroot/ *&lt;br /&gt;&amp;nbsp;&lt;br /&gt;-i: edits the files in place instead of printing to stdout&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb99531&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All 50 documents updated, simple as that.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>This week, after refactoring some XML based Java classes, I was left with ~50 XML documents (used for testing) with the wrong root element. After a few seconds pondering opening a text editor and find/replacing 50 times I had a better idea: <a href="http://www.gnu.org/software/sed/manual/sed.html">sed</a>.</p>

<p>sed can be used to perform regular expressions on each line of a file (or files). To solve the problem all it took was:</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb78648'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb78648','cb41479'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb78648" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">sed -i s/oldroot/newroot/ *</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">-i: edits the files in place instead of printing to stdout</li></ol></div><div id="cb41479" style="display: none; color: red;"></div></div></div>

<p>All 50 documents updated, simple as that.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/SysAdmins/OS/Linux/bulk-editing-with-sed#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/SysAdmins/?tempskin=_rss2&#38;disp=comments&#38;p=1229</wfw:commentRss>
		</item>
				<item>
			<title>Catching Key Conflicts with Perl's Class::DBI</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/catching-key-conflicts-with-perl</link>
			<pubDate>Mon, 31 Jan 2011 09:52:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Server Programming</category>			<guid isPermaLink="false">1094@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;When inserting to a database I find it more convenient to catch a key conflict than to perform a select in order to check for duplicates. Defining a column as unique will ensure data integrity at the lowest level.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;sql&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;sql&quot; id=&quot;cb35435&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;TABLE&lt;/span&gt; customer &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;id int &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;AUTO_INCREMENT&lt;/span&gt;, &lt;br /&gt;name varchar&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;br /&gt;address varchar&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;br /&gt;email varchar&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;br /&gt;constraint &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;KEY&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;id&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;br /&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;UNIQUE&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;email&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb50198&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Catching a user attempting to register with an email address which is already in the database is fairly simple when using DBI:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb7246&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$dbh&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;do&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/qq.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;qq&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;INSERT INTO customer &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; name, address, email &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; VALUES &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;?,?,?&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;, &lt;a href=&quot;http://perldoc.perl.org/functions/undef.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;undef&lt;/span&gt;&lt;/a&gt;, &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Rob&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Rob&#039;s House&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\@&lt;/span&gt;email.com&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Returns undef on error.&lt;/span&gt;&lt;br /&gt;&amp;amp;error&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$dbh&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;errstr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;unless&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Forward to error handler.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb4626&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;http://search.cpan.org/~tmtm/Class-DBI-v3.0.17/lib/Class/DBI.pm&quot;&gt;Class::DBI&lt;/a&gt; is a database abstraction Perl module. It wasn&#039;t immediately apparent to me how to handle a key conflict when using it. After a little investigation I found key violations will trigger an exception which makes it fairly simple to handle:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb10718&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/eval.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;eval&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$new_cust&lt;/span&gt; = Customer-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;insert&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;name=&amp;gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Rob&amp;quot;&lt;/span&gt;, address=&amp;gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Rob&#039;s House&amp;quot;&lt;/span&gt;, email=&amp;gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;my&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\@&lt;/span&gt;email.com&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Insert using Class::DBI constructor.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;; &amp;amp;error&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;$@&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; $@; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Forward to error handler.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb51801&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The eval block will catch the thrown exception, allowing you to gracefully handle it through your own subroutine.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/catching-key-conflicts-with-perl&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>When inserting to a database I find it more convenient to catch a key conflict than to perform a select in order to check for duplicates. Defining a column as unique will ensure data integrity at the lowest level.</p>

<div class="codebox"><div class="codeheader"><span>sql</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb34263'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb34263','cb94428'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="sql" id="cb34263" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> customer <span style="color: #66cc66;">&#40;</span></li><li style="" class="li2">id int <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>, </li><li style="" class="li1">name varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>, </li><li style="" class="li2">address varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>, </li><li style="" class="li1">email varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>, </li><li style="" class="li2">constraint <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>, </li><li style="" class="li1"><span style="color: #993333; font-weight: bold;">UNIQUE</span><span style="color: #66cc66;">&#40;</span>email<span style="color: #66cc66;">&#41;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb94428" style="display: none; color: red;"></div></div></div><p> </p>

<p>Catching a user attempting to register with an email address which is already in the database is fairly simple when using DBI:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb63214'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb63214','cb43344'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb63214" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$row</span> = <span style="color: #0000ff;">$dbh</span>-&gt;<span style="color: #006600;">do</span><span style="color: #66cc66;">&#40;</span><a href="http://perldoc.perl.org/functions/qq.html"><span style="color: #000066;">qq</span></a><span style="color: #66cc66;">&#123;</span>INSERT INTO customer <span style="color: #66cc66;">&#40;</span> name, address, email <span style="color: #66cc66;">&#41;</span> VALUES <span style="color: #66cc66;">&#40;</span>?,?,?<span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>, <a href="http://perldoc.perl.org/functions/undef.html"><span style="color: #000066;">undef</span></a>, <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Rob&quot;</span>, <span style="color: #ff0000;">&quot;Rob's House&quot;</span>, <span style="color: #ff0000;">&quot;my<span style="color: #000099; font-weight: bold;">\@</span>email.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;"># Returns undef on error.</span></li><li style="" class="li2">&amp;error<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dbh</span>-&gt;<span style="color: #006600;">errstr</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$row</span>; <span style="color: #808080; font-style: italic;"># Forward to error handler.</span></li></ol></div><div id="cb43344" style="display: none; color: red;"></div></div></div>

<p><a href="http://search.cpan.org/~tmtm/Class-DBI-v3.0.17/lib/Class/DBI.pm">Class::DBI</a> is a database abstraction Perl module. It wasn't immediately apparent to me how to handle a key conflict when using it. After a little investigation I found key violations will trigger an exception which makes it fairly simple to handle:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb73564'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb73564','cb72863'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb73564" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><a href="http://perldoc.perl.org/functions/eval.html"><span style="color: #000066;">eval</span></a></li><li style="" class="li2"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$new_cust</span> = Customer-&gt;<span style="color: #006600;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>name=&gt;<span style="color: #ff0000;">&quot;Rob&quot;</span>, address=&gt;<span style="color: #ff0000;">&quot;Rob's House&quot;</span>, email=&gt;<span style="color: #ff0000;">&quot;my<span style="color: #000099; font-weight: bold;">\@</span>email.com&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;"># Insert using Class::DBI constructor.</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span>; &amp;error<span style="color: #66cc66;">&#40;</span>$@<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">if</span> $@; <span style="color: #808080; font-style: italic;"># Forward to error handler.</span></li></ol></div><div id="cb72863" style="display: none; color: red;"></div></div></div>

<p>The eval block will catch the thrown exception, allowing you to gracefully handle it through your own subroutine.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/catching-key-conflicts-with-perl">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/catching-key-conflicts-with-perl#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1094</wfw:commentRss>
		</item>
				<item>
			<title>Writing Perl Tests with Test::More</title>
			<link>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test</link>
			<pubDate>Sat, 15 Jan 2011 14:29:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Server Programming</category>			<guid isPermaLink="false">1073@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;Writing tests for code is just as important as writing the code itself. Time spent writing tests is less time spent tracking down and fixing bugs, making it a great investment. Despite knowing this it can sometimes be hard to force yourself to stop coding and write tests. Fortunately, Perl has some modules to make it pretty simple. Here&#039;s the module we&#039;re going to be testing:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb40591&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;a href=&quot;http://perldoc.perl.org/functions/package.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;package&lt;/span&gt;&lt;/a&gt; MyMaths;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; strict;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$proto&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/ref.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ref&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$proto&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; || &lt;span style=&quot;color: #0000ff;&quot;&gt;$proto&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt; = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/bless.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;bless&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$class&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;sub&lt;/span&gt; add&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$self&lt;/span&gt; = &lt;a href=&quot;http://perldoc.perl.org/functions/shift.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;shift&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$total&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;my&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$factor&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;@_&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$total&lt;/span&gt; += &lt;span style=&quot;color: #0000ff;&quot;&gt;$factor&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://perldoc.perl.org/functions/return.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;return&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$total&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb7307&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see, we have a simple class with one method, add, which adds together all the arguments passed to it. We now need to define a test file for this module, called mymaths.t:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb59468&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Test::&lt;span style=&quot;color: #006600;&quot;&gt;More&lt;/span&gt; tests=&amp;gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; MyMaths;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; MyMaths;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1 + 2 + 3 = 6&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;8&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;6 + 2 = 8&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1 + 2 + 3 + 4 = 10&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1 + 2 = 3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2 = 2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;is&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$mymaths&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;-1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2 + -1 = 1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb99050&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This test file uses the is() method of the builtin Test::More module. This method takes 3 arguments: the test, the expected result and a description. If a test fails, is() will give some feedback on the test.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;edit:&lt;/strong&gt; To run the tests use the `prove` utility which is part of the Test::Harness package:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;codespan&quot;&gt;prove -v mymaths.t&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run all tests in the current directory with:&lt;br /&gt;
&lt;code class=&quot;codespan&quot;&gt;prove -v .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;del cite=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test#c7568&quot;&gt;To run the tests we use another builtin module, Test::Harness. Create tests.pl:&lt;/del&gt;&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;perl&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;perl&quot; id=&quot;cb47757&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;use&lt;/span&gt; Test::&lt;span style=&quot;color: #006600;&quot;&gt;Harness&lt;/span&gt; &lt;a href=&quot;http://perldoc.perl.org/functions/qw.html&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;qw&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;amp;runtests&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;@tests&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;@ARGV&lt;/span&gt; ? &lt;span style=&quot;color: #0000ff;&quot;&gt;@ARGV&lt;/span&gt; : &amp;lt;*.t&amp;gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;runtests &lt;span style=&quot;color: #0000ff;&quot;&gt;@tests&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb3606&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;del&gt;This script can either be run with a list of test files as arguments, or with no arguments to run all test files. Running the script results in:&lt;/del&gt;&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb7547&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;./mymaths.t .. &lt;br /&gt;1..6&lt;br /&gt;ok 1 - 1 + 2 + 3 = 6&lt;br /&gt;ok 2 - 6 + 2 = 8&lt;br /&gt;ok 3 - 1 + 2 + 3 + 4 = 10&lt;br /&gt;ok 4 - 1 + 2 = 3&lt;br /&gt;ok 5 - 2 = 2&lt;br /&gt;ok 6 - 2 + -1 = 1&lt;br /&gt;ok&lt;br /&gt;All tests successful.&lt;br /&gt;Files=1, Tests=6, &amp;nbsp;0 wallclock secs ( 0.01 usr &amp;nbsp;0.02 sys + &amp;nbsp;0.02 cusr &amp;nbsp;0.01 csys = &amp;nbsp;0.06 CPU)&lt;br /&gt;Result: PASS&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb88870&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Everything went fine, as expected. Now go back to the original class definition and make a typo on line 22, so it reads = instead of += and rerun the tests:&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb63940&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;./mymaths.t .. &lt;br /&gt;1..6&lt;br /&gt;not ok 1 - 1 + 2 + 3 = 6&lt;br /&gt;not ok 2 - 6 + 2 = 8&lt;br /&gt;not ok 3 - 1 + 2 + 3 + 4 = 10&lt;br /&gt;not ok 4 - 1 + 2 = 3&lt;br /&gt;ok 5 - 2 = 2&lt;br /&gt;not ok 6 - 2 + -1 = 1&lt;br /&gt;&amp;nbsp;&lt;br /&gt;# &amp;nbsp; Failed test &#039;1 + 2 + 3 = 6&#039;&lt;br /&gt;# &amp;nbsp; at ./mymaths.t line 7.&lt;br /&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;got: &#039;3&#039;&lt;br /&gt;# &amp;nbsp; &amp;nbsp; expected: &#039;6&#039;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;# &amp;nbsp; Failed test &#039;6 + 2 = 8&#039;&lt;br /&gt;# &amp;nbsp; at ./mymaths.t line 8.&lt;br /&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;got: &#039;2&#039;&lt;br /&gt;# &amp;nbsp; &amp;nbsp; expected: &#039;8&#039;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;# &amp;nbsp; Failed test &#039;1 + 2 + 3 + 4 = 10&#039;&lt;br /&gt;# &amp;nbsp; at ./mymaths.t line 9.&lt;br /&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;got: &#039;4&#039;&lt;br /&gt;# &amp;nbsp; &amp;nbsp; expected: &#039;10&#039;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;# &amp;nbsp; Failed test &#039;1 + 2 = 3&#039;&lt;br /&gt;# &amp;nbsp; at ./mymaths.t line 10.&lt;br /&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;got: &#039;2&#039;&lt;br /&gt;# &amp;nbsp; &amp;nbsp; expected: &#039;3&#039;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;# &amp;nbsp; Failed test &#039;2 + -1 = 1&#039;&lt;br /&gt;# &amp;nbsp; at ./mymaths.t line 12.&lt;br /&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;got: &#039;-1&#039;&lt;br /&gt;# &amp;nbsp; &amp;nbsp; expected: &#039;1&#039;&lt;br /&gt;# Looks like you failed 5 tests of 6.&lt;br /&gt;Dubious, test returned 5 (wstat 1280, 0x500)&lt;br /&gt;Failed 5/6 subtests &lt;br /&gt;&amp;nbsp;&lt;br /&gt;Test Summary Report&lt;br /&gt;-------------------&lt;br /&gt;./mymaths.t (Wstat: 1280 Tests: 6 Failed: 5)&lt;br /&gt;&amp;nbsp; Failed tests: &amp;nbsp;1-4, 6&lt;br /&gt;&amp;nbsp; Non-zero exit status: 5&lt;br /&gt;Files=1, Tests=6, &amp;nbsp;0 wallclock secs ( 0.03 usr &amp;nbsp;0.00 sys + &amp;nbsp;0.03 cusr &amp;nbsp;0.00 csys = &amp;nbsp;0.06 CPU)&lt;br /&gt;Result: FAIL&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb48637&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Most of the tests failed and gave good feedback to help find the problem.&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;Although writing tests can be a chore it is worth doing. If you write tests a little at a time:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When you design a class.&lt;/li&gt;
&lt;li&gt;When you add a method to a class.&lt;/li&gt;
&lt;li&gt;When you find a bug.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You&#039;ll develop a good library of tests without too much effort.&lt;/p&gt;

&lt;p&gt;Further reading: &lt;a href=&quot;http://perldoc.perl.org/Test/More.html&quot;&gt;Test::More perldoc&lt;/a&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>Writing tests for code is just as important as writing the code itself. Time spent writing tests is less time spent tracking down and fixing bugs, making it a great investment. Despite knowing this it can sometimes be hard to force yourself to stop coding and write tests. Fortunately, Perl has some modules to make it pretty simple. Here's the module we're going to be testing:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb98303'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb98303','cb50826'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb98303" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><a href="http://perldoc.perl.org/functions/package.html"><span style="color: #000066;">package</span></a> MyMaths;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> strict;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span></li><li style="" class="li1"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$proto</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$class</span> = <a href="http://perldoc.perl.org/functions/ref.html"><span style="color: #000066;">ref</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$proto</span><span style="color: #66cc66;">&#41;</span> || <span style="color: #0000ff;">$proto</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/bless.html"><span style="color: #000066;">bless</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$self</span>, <span style="color: #0000ff;">$class</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$self</span>;</li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">sub</span> add</li><li style="" class="li1"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> = <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$total</span> = <span style="color: #cc66cc;">0</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$factor</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@_</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$total</span> += <span style="color: #0000ff;">$factor</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$total</span>;</li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #cc66cc;">1</span>;</li></ol></div><div id="cb50826" style="display: none; color: red;"></div></div></div>

<p>As you can see, we have a simple class with one method, add, which adds together all the arguments passed to it. We now need to define a test file for this module, called mymaths.t:</p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb34056'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb34056','cb92778'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb34056" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Test::<span style="color: #006600;">More</span> tests=&gt;<span style="color: #cc66cc;">6</span>;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">use</span> MyMaths;</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0000ff;">$mymaths</span> = <span style="color: #000000; font-weight: bold;">new</span> MyMaths;</li><li style="" class="li1">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #ff0000;">&quot;1 + 2 + 3 = 6&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">8</span>,<span style="color: #ff0000;">&quot;6 + 2 = 8&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">10</span>, <span style="color: #ff0000;">&quot;1 + 2 + 3 + 4 = 10&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #ff0000;">&quot;1 + 2 = 3&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #ff0000;">&quot;2 = 2&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">is<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$mymaths</span>-&gt;<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #ff0000;">&quot;2 + -1 = 1&quot;</span><span style="color: #66cc66;">&#41;</span>;</li></ol></div><div id="cb92778" style="display: none; color: red;"></div></div></div>

<p>This test file uses the is() method of the builtin Test::More module. This method takes 3 arguments: the test, the expected result and a description. If a test fails, is() will give some feedback on the test.</p>

<p><strong>edit:</strong> To run the tests use the `prove` utility which is part of the Test::Harness package:</p>

<p><code class="codespan">prove -v mymaths.t</code></p>

<p>Run all tests in the current directory with:<br />
<code class="codespan">prove -v .</code></p>

<p><del cite="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test#c7568">To run the tests we use another builtin module, Test::Harness. Create tests.pl:</del></p>

<div class="codebox"><div class="codeheader"><span>perl</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb69787'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb69787','cb29238'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="perl" id="cb69787" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">use</span> Test::<span style="color: #006600;">Harness</span> <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #66cc66;">&#40;</span>&amp;runtests<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0000ff;">@tests</span> = <span style="color: #0000ff;">@ARGV</span> ? <span style="color: #0000ff;">@ARGV</span> : &lt;*.t&gt;;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">runtests <span style="color: #0000ff;">@tests</span>;</li></ol></div><div id="cb29238" style="display: none; color: red;"></div></div></div>

<p><del>This script can either be run with a list of test files as arguments, or with no arguments to run all test files. Running the script results in:</del></p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb92309'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb92309','cb48435'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb92309" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">./mymaths.t .. </li><li style="" class="li2">1..6</li><li style="" class="li1">ok 1 - 1 + 2 + 3 = 6</li><li style="" class="li2">ok 2 - 6 + 2 = 8</li><li style="" class="li1">ok 3 - 1 + 2 + 3 + 4 = 10</li><li style="" class="li2">ok 4 - 1 + 2 = 3</li><li style="" class="li1">ok 5 - 2 = 2</li><li style="" class="li2">ok 6 - 2 + -1 = 1</li><li style="" class="li1">ok</li><li style="" class="li2">All tests successful.</li><li style="" class="li1">Files=1, Tests=6, &nbsp;0 wallclock secs ( 0.01 usr &nbsp;0.02 sys + &nbsp;0.02 cusr &nbsp;0.01 csys = &nbsp;0.06 CPU)</li><li style="" class="li2">Result: PASS</li></ol></div><div id="cb48435" style="display: none; color: red;"></div></div></div>

<p>Everything went fine, as expected. Now go back to the original class definition and make a typo on line 22, so it reads = instead of += and rerun the tests:</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb70718'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb70718','cb27745'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb70718" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">./mymaths.t .. </li><li style="" class="li2">1..6</li><li style="" class="li1">not ok 1 - 1 + 2 + 3 = 6</li><li style="" class="li2">not ok 2 - 6 + 2 = 8</li><li style="" class="li1">not ok 3 - 1 + 2 + 3 + 4 = 10</li><li style="" class="li2">not ok 4 - 1 + 2 = 3</li><li style="" class="li1">ok 5 - 2 = 2</li><li style="" class="li2">not ok 6 - 2 + -1 = 1</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"># &nbsp; Failed test '1 + 2 + 3 = 6'</li><li style="" class="li1"># &nbsp; at ./mymaths.t line 7.</li><li style="" class="li2"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;got: '3'</li><li style="" class="li1"># &nbsp; &nbsp; expected: '6'</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"># &nbsp; Failed test '6 + 2 = 8'</li><li style="" class="li2"># &nbsp; at ./mymaths.t line 8.</li><li style="" class="li1"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;got: '2'</li><li style="" class="li2"># &nbsp; &nbsp; expected: '8'</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"># &nbsp; Failed test '1 + 2 + 3 + 4 = 10'</li><li style="" class="li1"># &nbsp; at ./mymaths.t line 9.</li><li style="" class="li2"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;got: '4'</li><li style="" class="li1"># &nbsp; &nbsp; expected: '10'</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"># &nbsp; Failed test '1 + 2 = 3'</li><li style="" class="li2"># &nbsp; at ./mymaths.t line 10.</li><li style="" class="li1"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;got: '2'</li><li style="" class="li2"># &nbsp; &nbsp; expected: '3'</li><li style="" class="li1">&nbsp;</li><li style="" class="li2"># &nbsp; Failed test '2 + -1 = 1'</li><li style="" class="li1"># &nbsp; at ./mymaths.t line 12.</li><li style="" class="li2"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;got: '-1'</li><li style="" class="li1"># &nbsp; &nbsp; expected: '1'</li><li style="" class="li2"># Looks like you failed 5 tests of 6.</li><li style="" class="li1">Dubious, test returned 5 (wstat 1280, 0x500)</li><li style="" class="li2">Failed 5/6 subtests </li><li style="" class="li1">&nbsp;</li><li style="" class="li2">Test Summary Report</li><li style="" class="li1">-------------------</li><li style="" class="li2">./mymaths.t (Wstat: 1280 Tests: 6 Failed: 5)</li><li style="" class="li1">&nbsp; Failed tests: &nbsp;1-4, 6</li><li style="" class="li2">&nbsp; Non-zero exit status: 5</li><li style="" class="li1">Files=1, Tests=6, &nbsp;0 wallclock secs ( 0.03 usr &nbsp;0.00 sys + &nbsp;0.03 cusr &nbsp;0.00 csys = &nbsp;0.06 CPU)</li><li style="" class="li2">Result: FAIL</li></ol></div><div id="cb27745" style="display: none; color: red;"></div></div></div>

<p>Most of the tests failed and gave good feedback to help find the problem.</p>

<h2>Summary</h2>

<p>Although writing tests can be a chore it is worth doing. If you write tests a little at a time:</p>
<ul>
<li>When you design a class.</li>
<li>When you add a method to a class.</li>
<li>When you find a bug.</li>
</ul>

<p>You'll develop a good library of tests without too much effort.</p>

<p>Further reading: <a href="http://perldoc.perl.org/Test/More.html">Test::More perldoc</a></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/writing-perl-tests-with-test#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/WebDev/?tempskin=_rss2&#38;disp=comments&#38;p=1073</wfw:commentRss>
		</item>
				<item>
			<title>My First Android Application (Ubuntu Linux)</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/my-first-android-application-ubuntu</link>
			<pubDate>Wed, 05 Jan 2011 17:46:00 +0000</pubDate>			<dc:creator>Rob Earl</dc:creator>
			<category domain="main">Java</category>			<guid isPermaLink="false">1066@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;This post details my first adventure into developing for the Android platform and the steps taken to get the HelloWorld application to run.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Download the Linux SDK from: &lt;a href=&quot;http://developer.android.com/sdk/index.html&quot;&gt;http://developer.android.com/sdk/index.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Extract the archive and take note of the directory&lt;/li&gt;
&lt;li&gt;Install Eclipse (`apt-get install eclipse`)&lt;/li&gt;
&lt;li&gt;Install Eclipse plugin&lt;ol&gt;
&lt;li&gt;Help-&amp;gt;Install Software&lt;/li&gt;
&lt;li&gt;Add repository: &lt;a href=&quot;https://dl-ssl.google.com/android/eclipse&quot;&gt;https://dl-ssl.google.com/android/eclipse&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Select Developer Tools&lt;/li&gt;
&lt;li&gt;Read and accept licenses&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Configure Eclipse&lt;ol&gt;
&lt;li&gt;Windows-&amp;gt;Preferences-&amp;gt;Android&lt;/li&gt;
&lt;li&gt;Set SDK Location&lt;/li&gt;
&lt;li&gt;Select OK&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Setup SDK and Virtual Device&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;From Eclipse: Window-&amp;gt;Android SDK and AVD Manager-&amp;gt;Available Packages&lt;/li&gt;
&lt;li&gt;Select Android Repository-&amp;gt;Install Selected&lt;/li&gt;
&lt;li&gt;Select Virtual devices-&amp;gt;New: Name the device and select the target API version&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Create Android Project in Eclipse&lt;ol&gt;
&lt;li&gt;Project name: HelloAndroid&lt;/li&gt;
&lt;li&gt;Application name: Hello&lt;/li&gt;
&lt;li&gt;Package name: com.example.helloandroid&lt;/li&gt;
&lt;li&gt;Create Activity: HelloAndroid&lt;/li&gt;
&lt;li&gt;Build Target: Same as the target as selected for Virtual Device&lt;/li&gt;
&lt;/ol&gt; &lt;/li&gt;
&lt;li&gt;Add the code below to src/com.example.helloandroid/HelloAndroid.java&lt;/li&gt;
&lt;li&gt;Create a new Runtime configuration&lt;ol&gt;
&lt;li&gt;Run-&amp;gt;Run Configurations-&amp;gt;Android-&amp;gt;New&lt;/li&gt;
&lt;li&gt;Project: HelloAndroid&lt;/li&gt;
&lt;li&gt;Select Target tab and choose the Virtual Device configured earlier&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Run!&lt;/li&gt;
&lt;li&gt;After a couple of minutes the emulator should boot and display the HelloWorld application (You may need to unlock the screen first)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;h2&gt;HelloAndroid.java&lt;/h2&gt;
&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb98634&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; com.&lt;span style=&quot;color: #006600;&quot;&gt;example&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;helloandroid&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import android.app.Activity;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import android.os.Bundle;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import android.widget.TextView;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; HelloAndroid &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;extends&lt;/span&gt; Activity &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/** Called when the activity is first created. */&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;@Override&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;void&lt;/span&gt; onCreate&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Bundle savedInstanceState&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;super&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;onCreate&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;savedInstanceState&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TextView tv = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; TextView&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tv.&lt;span style=&quot;color: #006600;&quot;&gt;setText&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Hello, Android&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;setContentView&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;tv&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb77964&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;For more information see the Android development documentation:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://developer.android.com/sdk/installing.html&quot;&gt;http://developer.android.com/sdk/installing.html&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://developer.android.com/sdk/eclipse-adt.html#installing&quot;&gt;http://developer.android.com/sdk/eclipse-adt.html#installing&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://developer.android.com/resources/tutorials/hello-world.html&quot;&gt;http://developer.android.com/resources/tutorials/hello-world.html&lt;/a&gt;&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/my-first-android-application-ubuntu&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>This post details my first adventure into developing for the Android platform and the steps taken to get the HelloWorld application to run.</p>
<ol>
<li>Download the Linux SDK from: <a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a></li>
<li>Extract the archive and take note of the directory</li>
<li>Install Eclipse (`apt-get install eclipse`)</li>
<li>Install Eclipse plugin<ol>
<li>Help-&gt;Install Software</li>
<li>Add repository: <a href="https://dl-ssl.google.com/android/eclipse">https://dl-ssl.google.com/android/eclipse</a></li>
<li>Select Developer Tools</li>
<li>Read and accept licenses</li>
</ol></li>
<li>Configure Eclipse<ol>
<li>Windows-&gt;Preferences-&gt;Android</li>
<li>Set SDK Location</li>
<li>Select OK</li>
</ol></li>
<li>Setup SDK and Virtual Device<br /><ol>
<li>From Eclipse: Window-&gt;Android SDK and AVD Manager-&gt;Available Packages</li>
<li>Select Android Repository-&gt;Install Selected</li>
<li>Select Virtual devices-&gt;New: Name the device and select the target API version</li>
</ol></li>
<li>Create Android Project in Eclipse<ol>
<li>Project name: HelloAndroid</li>
<li>Application name: Hello</li>
<li>Package name: com.example.helloandroid</li>
<li>Create Activity: HelloAndroid</li>
<li>Build Target: Same as the target as selected for Virtual Device</li>
</ol> </li>
<li>Add the code below to src/com.example.helloandroid/HelloAndroid.java</li>
<li>Create a new Runtime configuration<ol>
<li>Run-&gt;Run Configurations-&gt;Android-&gt;New</li>
<li>Project: HelloAndroid</li>
<li>Select Target tab and choose the Virtual Device configured earlier</li>
</ol></li>
<li>Run!</li>
<li>After a couple of minutes the emulator should boot and display the HelloWorld application (You may need to unlock the screen first)</li>
</ol>
<p>&#160;</p>
<h2>HelloAndroid.java</h2>
<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb32371'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb32371','cb9352'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb32371" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">example</span>.<span style="color: #006600;">helloandroid</span>;</li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #a1a100;">import android.app.Activity;</span></li><li style="" class="li2"><span style="color: #a1a100;">import android.os.Bundle;</span></li><li style="" class="li1"><span style="color: #a1a100;">import android.widget.TextView;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloAndroid <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">/** Called when the activity is first created. */</span></li><li style="" class="li1">&nbsp; &nbsp;@Override</li><li style="" class="li2">&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> onCreate<span style="color: #66cc66;">&#40;</span>Bundle savedInstanceState<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006600;">onCreate</span><span style="color: #66cc66;">&#40;</span>savedInstanceState<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp;TextView tv = <span style="color: #000000; font-weight: bold;">new</span> TextView<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp;tv.<span style="color: #006600;">setText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hello, Android&quot;</span><span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp;setContentView<span style="color: #66cc66;">&#40;</span>tv<span style="color: #66cc66;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp;<span style="color: #66cc66;">&#125;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb9352" style="display: none; color: red;"></div></div></div>


<p>For more information see the Android development documentation:</p>
<p><a href="http://developer.android.com/sdk/installing.html">http://developer.android.com/sdk/installing.html</a><br /><a href="http://developer.android.com/sdk/eclipse-adt.html#installing">http://developer.android.com/sdk/eclipse-adt.html#installing</a><br /><a href="http://developer.android.com/resources/tutorials/hello-world.html">http://developer.android.com/resources/tutorials/hello-world.html</a></p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/my-first-android-application-ubuntu">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/my-first-android-application-ubuntu#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1066</wfw:commentRss>
		</item>
			</channel>
</rss>
