<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Foolish Manifesto &#187; perl</title>
	<atom:link href="http://blog.afoolishmanifesto.com/archives/category/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.afoolishmanifesto.com</link>
	<description>fREWdiculous!</description>
	<lastBuildDate>Fri, 30 Jul 2010 02:57:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CPAN Mashup?</title>
		<link>http://blog.afoolishmanifesto.com/archives/786</link>
		<comments>http://blog.afoolishmanifesto.com/archives/786#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:16:06 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[cpan]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=786</guid>
		<description><![CDATA[One of the common issues I hear about CPAN is that it&#8217;s so sprawling that people do not know which modules to use and which not to use. Hopefully part of that issue will be solved by the Enlightened Perl Core, but that will only go so far. Recently there were a couple posts regarding [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common issues I hear about CPAN is that it&#8217;s so sprawling that people do not know which modules to use and which not to use.  Hopefully part of that issue will be solved by the <a href="http://www.enlightenedperl.org/index.html">Enlightened Perl</a> Core, but that will only go so far.  Recently there were a <a href="http://lastofthecarelessmen.blogspot.com/2009/06/lost-in-cpan.html">couple</a> <a href="http://lastofthecarelessmen.blogspot.com/2009/06/guide-to-cpan-needed.html">posts</a> regarding this issue.  (Note: They are in reference to a post I made and they are from the same guy.)  I even recently had a discussion regarding this with my boss recently because we needed some barcode generation code.  <em>(We ended up using <a href="http://search.cpan.org/~wrw/Barcode-Code128-2.01/lib/Barcode/Code128.pm">Barcode::Code128</a> but we spent a lot of time trying to get GD::Barcode to do what we wanted.)</em>  Furthermore I chatted with the EPCore guys regarding this and they all helped me think through a lot of these issues; I have a muddled mind <img src='http://blog.afoolishmanifesto.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I think a solution to this problem is feasible.  I imagine a web service that will help recommend various packages for given tasks.  I have the following (pie in the sky) goals in mind:</p>
<ul>
<li>Automated and Objective (as much as possible)</li>
<li>Easy to Use</li>
<li>Fast</li>
<li>Configurable scoring (for people who don&#8217;t like the default metrics)</li>
</ul>
<p>Here are some possible sources of data to make this all work:</p>
<ul>
<li><a href="http://static.cpantesters.org/">CPAN Testers</a></li>
<li>CPAN Deps</li>
<li><a href="http://ruby-toolbox.com/">Github watches</a></li>
<li><a href="http://cpanratings.perl.org/">CPAN Ratings</a></li>
</ul>
<p>CPAN Testers is obvious.  It has massive amounts of data and it can at least tell you if a module is good by it&#8217;s own measure.  It might be worthwhile to look into some kind of scaling based on tests (configurable of course.)  The idea there is that if a module has never failed because it has no tests that shouldn&#8217;t count.</p>
<p>CPAN Deps isn&#8217;t even completed.  I&#8217;ve only heard this <a href="http://www.modernperlbooks.com/mt/2009/06/minimalism-for-maintenance-ecosystems-for-efficacy-a-graph-for-all.html">name dropped</a>, but the idea is clear.  With it you could find out what modules are <strong>effectively</strong> core in that lots of people depend on them.  You could use this in a PageRank style way in that modules that have a high score help add to the score of modules they depend on.</p>
<p>The Github watches link that I posted is where I originally got the idea for this.  I&#8217;m not really sold on it, but mst liked it so much I figured I&#8217;d keep it in the list; I wish I could give you a link to the actual conversation.  He hated the idea of using &#8220;failhub&#8221; <img src='http://blog.afoolishmanifesto.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   I <strong>do</strong> like the idea, but I am certainly not as smart or motivated as mst.</p>
<p>And last but certainly not least, CPAN Ratings. CPAN Ratings is an excellent idea, but it needs some love.  Part of that has to do with it&#8217;s actual implementation (at the very least it&#8217;s ugly,) but the real issue is the use of it.  More people need to use it.  I don&#8217;t know how to do that other than to use it myself.  I think it might be good if, after using a module for at least an iteration, I rated it.  If one were to rate a module too soon the results could become inflated.  And as a side-note, I personally think we should use OpenID instead of BitCard, but it&#8217;s not worth changing a bunch of stuff just for that.</p>
<p>And then I was thinking that we could use a combination of module name searching, tags added to META.yml, and tags added manually.  So DBIx::Class would theoretically add the ORM tag (and others possibly) to their META.yml, and then someone would manually add the tag to Class::DBI.  Then when people search for ORM they would at least find those two.  They would then get a score based on the previous five metrics.  I would say have anything with a score beneath a certain number not even displayed, but have a link that would allow the display; and maybe a user option that would permanently display hidden items.</p>
<p>I think this is something that would certainly be worth attempting.  It wouldn&#8217;t be easy, and the stuff I&#8217;ve said above is certainly riddled with errors, but that shouldn&#8217;t stop us.  What do you guys think?  Other ideas for data sources?  Implementation ideas?  Tuits?</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/1066" rel="bookmark" class="crp_title">CPAN Ratings Day</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1100" rel="bookmark" class="crp_title">How to Help without being a Rockstar</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/899" rel="bookmark" class="crp_title">Model Based Security</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1124" rel="bookmark" class="crp_title">On Moose and Speed</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1331" rel="bookmark" class="crp_title">How CPAN (and Open Source) works</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/786/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Web Comic Downloaders</title>
		<link>http://blog.afoolishmanifesto.com/archives/770</link>
		<comments>http://blog.afoolishmanifesto.com/archives/770#comments</comments>
		<pubDate>Tue, 02 Jun 2009 05:08:31 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[webcomics]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=770</guid>
		<description><![CDATA[Since the beginning of my serious webcomic journey with xkcd, I think that was four years ago, I&#8217;ve been writing little scripts to help me get started. The first type of script is to grab integer-based, monotonically increasing files. Very easy. Done in Ruby. 1234567#!/usr/bin/ruby -w Fromat = &#34;http://foobar.com/comics/%08d.gif&#34; 1.upto&#40;986&#41; do &#124;i&#124; &#160; `wget #{sprintf(Fromat, [...]]]></description>
			<content:encoded><![CDATA[<p>Since the beginning of my serious webcomic journey with xkcd, I think that was four years ago, I&#8217;ve been writing little scripts to help me get started.  The first type of script is to grab integer-based, monotonically increasing files.  Very easy. Done in Ruby.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby -w</span><br />
<br />
Fromat = <span style="color:#996600;">&quot;http://foobar.com/comics/%08d.gif&quot;</span><br />
<span style="color:#006666;">1</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">986</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; <span style="color:#996600;">`wget #{sprintf(Fromat, i)}`</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">1</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>The next harder are the ones that are based on the date of publication.  Usually though, they will be published Monday-Wed-Fri or something like that, so you can just increase per day and then check if it&#8217;s the correct weekday.  See more Ruby.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby -w</span><br />
<br />
Day = <span style="color:#006666;">60</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">60</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">24</span><br />
<br />
Fromat = <span style="color:#996600;">&quot;http://www.foobar.com/comics/st%Y%m%d.gif&quot;</span><br />
<br />
t = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">local</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2005</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
MWF = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">3</span>,<span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">until</span> t == <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">local</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2007</span>, <span style="color:#006666;">7</span>, <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> MWF.<span style="color:#9966CC; font-weight:bold;">include</span>? t.<span style="color:#9900CC;">wday</span><br />
&nbsp; &nbsp; <span style="color:#996600;">`wget #{t.strftime(Fromat)}`</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">3</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; t <span style="color:#006600; font-weight:bold;">+</span>= Day<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>And then lastly, and hardest of all, are arbitrary files that can only be ascertained by clicking links.  Perl + CPAN to the rescue!!!</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!perl</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> feature <span style="color: #ff0000;">':5.10'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Mechanize</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mech</span> <span style="color: #339933;">=</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Mechanize</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span> autocheck <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">sub</span> process_page <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@images</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">find_all_images</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; url_abs_regex <span style="color: #339933;">=&gt;</span> <a href="http://perldoc.perl.org/functions/qr.html"><span style="color: #000066;">qr</span></a><span style="color: #009900;">&#123;</span>http<span style="color: #339933;">://</span>www\<span style="color: #339933;">.</span>foobar\<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>memberimages<span style="color: #339933;">/.*</span>\<span style="color: #339933;">.</span>jpg<span style="color: #009900;">&#125;</span>i<br />
&nbsp; &nbsp;<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@images</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">url</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$url</span> <span style="color: #339933;">!~</span> <span style="color: #009966; font-style: italic;">qr/banner/i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;say <span style="color: #ff0000;">&quot;downloading $url&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/qx.html"><span style="color: #000066;">qx</span></a><span style="color: #009900;">&#123;</span>wget <span style="color: #0000ff;">$url</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'http://www.foobar.com/foo/bar/series.php?view=single&amp;ID=72709'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
process_page<span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$mech</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">follow_link</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># third link on page matching regex</span><br />
&nbsp; &nbsp; &nbsp; n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; url_abs_regex <span style="color: #339933;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/qr.html"><span style="color: #000066;">qr</span></a><span style="color: #009900;">&#123;</span>http<span style="color: #339933;">://</span>www\<span style="color: #339933;">.</span>webcomicsnation\<span style="color: #339933;">.</span>com<span style="color: #339933;">/</span>dmeconis<span style="color: #339933;">/</span>familyman<span style="color: #339933;">/</span>series\<span style="color: #339933;">.</span>php\<span style="color: #339933;">?</span>view<span style="color: #339933;">=</span>single<span style="color: #0000ff;">&amp;ID</span><span style="color: #339933;">=</span><span style="color: #0000ff;">\d</span><span style="color: #339933;">+</span><span style="color: #009900;">&#125;</span>i<br />
&nbsp; &nbsp;<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/sleep.html"><span style="color: #000066;">sleep</span></a> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;process_page<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>This last one should be checked on every now and then as it is easy for it to get stuck in an infinite loop on the last couple comics.</p>
<p>Anyway, enjoy!  This set of scripts should take care of all of your webcomic scraping needs <img src='http://blog.afoolishmanifesto.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Note: these are not to avoid ads, but to speed up the initial reading process as speed is an issue when reading 400 or more strips.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/88" rel="bookmark" class="crp_title">Ruby1.8 vs. Perl6</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/49" rel="bookmark" class="crp_title">Ruby 1.9 is out!</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/4" rel="bookmark" class="crp_title">Friday Tips and Tricks</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/939" rel="bookmark" class="crp_title">Speed, OO, Black Magic, and YAGNI + RTFM</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/847" rel="bookmark" class="crp_title">YAPC Day 1</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/770/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Script to Rename MP3&#8242;s</title>
		<link>http://blog.afoolishmanifesto.com/archives/764</link>
		<comments>http://blog.afoolishmanifesto.com/archives/764#comments</comments>
		<pubDate>Sun, 31 May 2009 22:37:34 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=764</guid>
		<description><![CDATA[I recently got a new car stereo due to the other one being stolen. I am almost entirely happy with the model that I ended up purchasing, but one thing that it does, which is really obnoxious, is that it doesn&#8217;t sort the files correctly unless the track number is early on in the file [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got a new car stereo due to the other one being stolen.  I am almost entirely happy with the model that I ended up purchasing, but one thing that it does, which is really obnoxious, is that it doesn&#8217;t sort the files correctly unless the track number is early on in the file name.  Even if all tracks are &#8220;FooBarBaz 01 &#8211; name.mp3&#8243; it seems to ignore the number unless it&#8217;s the very beginning of the file name.  Anyway, easy fix:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!perl</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> feature <span style="color: #ff0000;">':5.10'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> Music<span style="color: #339933;">::</span><span style="color: #006600;">Tag</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Find</span><span style="color: #339933;">::</span><span style="color: #006600;">Rule</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span> <span style="color: #ff0000;">&quot;fileparse&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Copy</span> <span style="color: #ff0000;">&quot;move&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Spec</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$directory</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a> <span style="color: #339933;">||</span> <span style="color: #ff0000;">'.'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@songs</span><br />
&nbsp; &nbsp;<span style="color: #339933;">=</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Find</span><span style="color: #339933;">::</span><span style="color: #006600;">Rule</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">file</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">'*.mp3'</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #339933;">-&gt;</span><span style="color: #006600;">in</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$directory</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$song</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@songs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$info</span> <span style="color: #339933;">=</span> Music<span style="color: #339933;">::</span><span style="color: #006600;">Tag</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$song</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_tag</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$track</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">track</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">title</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/undef.html"><span style="color: #000066;">undef</span></a><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$suffix</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <br />
&nbsp; &nbsp; &nbsp; fileparse<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$song</span><span style="color: #339933;">,</span> <span style="color: #009966; font-style: italic;">qr/\.[^.]*/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">close</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$track</span> <span style="color: #b1b100;">and</span> <span style="color: #0000ff;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$newfilename</span> <span style="color: #339933;">=</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Spec</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">catfile</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">$dir</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/sprintf.html"><span style="color: #000066;">sprintf</span></a> <span style="color: #ff0000;">&quot;%02d %s%s&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$track</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$suffix</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$song</span> <span style="color: #b1b100;">ne</span> <span style="color: #0000ff;">$newfilename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;say <span style="color: #ff0000;">&quot;renaming $song to $newfilename&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;move <span style="color: #0000ff;">$song</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$newfilename</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>It doesn&#8217;t really deal with illegal characters, it just doesn&#8217;t rename those files.  Eventually I&#8217;ll get around to doing that.  Anyway, just figured someone might be interested/want to copy paste this.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/693" rel="bookmark" class="crp_title">Friday Refactor</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/586" rel="bookmark" class="crp_title">Perl::Tidy: annoying facts</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/156" rel="bookmark" class="crp_title">Album of the Week: To Watch the Storms</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/562" rel="bookmark" class="crp_title">More Tools Monday</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/518" rel="bookmark" class="crp_title">Vim Feature of the Day</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/764/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Repeat Yourself: JSON</title>
		<link>http://blog.afoolishmanifesto.com/archives/739</link>
		<comments>http://blog.afoolishmanifesto.com/archives/739#comments</comments>
		<pubDate>Tue, 19 May 2009 00:58:43 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=739</guid>
		<description><![CDATA[With DBIx::Class we typically have a TO_JSON method which returns a hashref of the data you want in your json. Here&#8217;s an example: 1234567891011121314sub TO_JSON &#123; &#160; &#160;my $self = shift; &#160; &#160;return &#123; &#160; &#160; &#160; id =&#62; $self-&#62;id, &#160; &#160; &#160; name =&#62; $self-&#62;name, &#160; &#160; &#160; comments =&#62; $self-&#62;comments, &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>With DBIx::Class we typically have a TO_JSON method which returns a hashref of the data you want in your json.  Here&#8217;s an example:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">sub</span> TO_JSON <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">id</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; name <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; comments <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">comments</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; email <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">email</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; job <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">job</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; ok <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">ok</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; i_cant <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">i_cant</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; think_of <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">think_ok</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; anymore <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">anymore</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Here&#8217;s the shorter version mst inspired me to write:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">sub</span> TO_JSON <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/map.html"><span style="color: #000066;">map</span></a> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$_</span> <span style="color: #339933;">=&gt;</span> self<span style="color: #339933;">-&gt;</span><span style="color: #0000ff;">$_</span> <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#123;</span> id name comments email job<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ok i_cant think_of anymore <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Anyway, not very complex, but still awesome.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/1273" rel="bookmark" class="crp_title">Solution on how to serialize dates nicely</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1269" rel="bookmark" class="crp_title">What is the right way to serialize X object generically?</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/503" rel="bookmark" class="crp_title">DBIx::Class: A Love Story</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1289" rel="bookmark" class="crp_title">New stuff in DBIx::Class::Helpers 2.00200</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/602" rel="bookmark" class="crp_title">Moose makes Perl OO Sexy!</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/739/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Perl 5 to Perl 6 Rewrite</title>
		<link>http://blog.afoolishmanifesto.com/archives/718</link>
		<comments>http://blog.afoolishmanifesto.com/archives/718#comments</comments>
		<pubDate>Fri, 15 May 2009 19:13:20 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[perl6]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=718</guid>
		<description><![CDATA[My coworker Wes asked me if there could be a nice refactor for the following function which checks CAS Numbers to ensure their validity. After struggling for 30 minutes I gave up trying to make it a little bit nicer with reduce. 1234567891011121314sub cas_old &#123; &#160; my $cas = shift; &#160; if &#40;$cas =~ /\d{1,8}-\d\d-\d/&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>My coworker Wes asked me if there could be a nice refactor for the following function which checks CAS Numbers to ensure their validity.  After struggling for 30 minutes I gave up trying to make it a little bit nicer with reduce.</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">sub</span> cas_old <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cas</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cas</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\d{1,8}-\d\d-\d/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@ary</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/grep.html"><span style="color: #000066;">grep</span></a> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$_</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">'-'</span> <span style="color: #009900;">&#125;</span> <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a><span style="color: #009900;">&#40;</span><span style="color: #339933;">//,</span> <span style="color: #0000ff;">$cas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$check</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/pop.html"><span style="color: #000066;">pop</span></a> <span style="color: #0000ff;">@ary</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$count</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@ary</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sum</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@ary</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$sum</span> <span style="color: #339933;">+=</span> <span style="color: #0000ff;">$_</span> <span style="color: #339933;">*</span> <span style="color: #0000ff;">$count</span><span style="color: #339933;">--;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$sum</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$check</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Let&#8217;s take a look at this and figure it out.  The crunchy bit is the for loop, so I&#8217;ll go through that.  Basically we are summing each item times a weight that is inversely proportional to it&#8217;s location in the list.  Or to be more explicit, let&#8217;s do an example on the board (7732-18-5.)  5 is the check digit.</p>
<table style="border-spacing: 10px;">
<thead>
<tr>
<th>$_</th>
<th>$count</th>
<th>$_ * $count</th>
<th>$sum</th>
</tr>
</thead>
<tbody>
<tr>
<td>7</td>
<td>6</td>
<td>42</td>
<td>42</td>
</tr>
<tr>
<td>7</td>
<td>5</td>
<td>35</td>
<td>77</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>12</td>
<td>89</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>6</td>
<td>95</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>2</td>
<td>97</td>
</tr>
<tr>
<td>8</td>
<td>1</td>
<td>8</td>
<td>105</td>
</tr>
</tbody>
</table>
<p>So basically we are making a special summation.  The thing that&#8217;s unusual is that we have a decrementing counter along with it.  If I had the control structure which I am about to show you in my mind already the solution might have jumped out sooner.</p>
<p>So I asked about it in #perl6 and it turns out there is a very nice Perl 6 version.  It takes advantage of the mystical hyperoperator (>>infix op<<); that is, it takes two lists and performs an operation on each element together.  Think SIMD.  It also uses reduce ([infix op]) which I have mentioned before.  Check it out!</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sub cas(Str $cas) {<br />
&nbsp; &nbsp; if $cas ~~ /(\d ** 1..8)\-(\d\d)\-(\d)/ {<br />
&nbsp; &nbsp; &nbsp; &nbsp; my @digits = $0~$1.split '';<br />
&nbsp; &nbsp; &nbsp; &nbsp; my $check = $2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; return ([+] @digits.reverse <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&gt;&gt;*&lt;&lt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(1..@digits)) % 10 == $check;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return Bool::False;<br />
}</div></td></tr></tbody></table></div>
<p>This does the same thing as above.  Or to put it in English, we take our digits, reverse them, and then multiply each digit (hyperoperator, >>*<<) by the respective integer in the other list, that is, 1 to the size of the list.  We then sum (reduce, [+]) that new list, and get the modulus 10 of it.</p>
<p>Very elegant, no?</p>
<p><strong>Update</strong>: Turns out there is also a very elegant version in p5, according to mst.  Check it out!</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">sub</span> cas_old <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">use</span> List<span style="color: #339933;">::</span><span style="color: #006600;">Util</span> <span style="color: #ff0000;">'sum'</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cas</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/shift.html"><span style="color: #000066;">shift</span></a><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cas</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(\d{1,8})-(\d\d)-(\d)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@digits</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a><span style="color: #009900;">&#40;</span><span style="color: #339933;">//,</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$count</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@digits</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$check</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$3</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #009900;">&#40;</span>sum <a href="http://perldoc.perl.org/functions/map.html"><span style="color: #000066;">map</span></a> <span style="color: #0000ff;">$_</span> <span style="color: #339933;">*</span> <span style="color: #0000ff;">$digits</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;">1</span> <span style="color: #339933;">..</span> <span style="color: #0000ff;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$check</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s very similar to the p6 version, just using fewer generalized operators, so you should be able to follow it fairly well.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/70" rel="bookmark" class="crp_title">Perl6 vs Ruby: reduce</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/868" rel="bookmark" class="crp_title">Finding the Optimum Meeting Location</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/49" rel="bookmark" class="crp_title">Ruby 1.9 is out!</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1033" rel="bookmark" class="crp_title">For Arcanez</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/85" rel="bookmark" class="crp_title">OLOTD</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/718/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dallas.p6m: May 2009</title>
		<link>http://blog.afoolishmanifesto.com/archives/706</link>
		<comments>http://blog.afoolishmanifesto.com/archives/706#comments</comments>
		<pubDate>Fri, 15 May 2009 05:41:35 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[dallas]]></category>
		<category><![CDATA[p6m]]></category>
		<category><![CDATA[perl6]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=706</guid>
		<description><![CDATA[We had the second Dallas.p6m on May 12, 2009. Along with me there were two of my coworkers, s1n, Graham Barr, and Patrick Michaud. We discussed a lot of things. One of which was the difference between subs and methods in Perl6. And the fact that you can&#8217;t imply self. This should explain it: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748class [...]]]></description>
			<content:encoded><![CDATA[<p>We had the second Dallas.p6m on May 12, 2009.  Along with me there were two of my coworkers, s1n, Graham Barr, and Patrick Michaud.  We discussed a lot of things.  One of which was the difference between <strong>subs and methods</strong> in Perl6.  And the fact that you can&#8217;t imply self.  This should explain it:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">class A {<br />
<br />
&nbsp; &nbsp;sub foo {<br />
&nbsp; &nbsp; &nbsp; say 'foo';<br />
&nbsp; &nbsp;}<br />
<br />
&nbsp; &nbsp;method bar($o:) {<br />
<br />
&nbsp; &nbsp; &nbsp; # much to s1n's chagrin, you can't<br />
&nbsp; &nbsp; &nbsp; # have baz() imply self.baz. &nbsp;These<br />
&nbsp; &nbsp; &nbsp; # are his options<br />
<br />
&nbsp; &nbsp; &nbsp; say 'bar';<br />
&nbsp; &nbsp; &nbsp; self.baz;<br />
&nbsp; &nbsp; &nbsp; $o.baz;<br />
<br />
&nbsp; &nbsp; &nbsp; # great for when you have a lot <br />
&nbsp; &nbsp; &nbsp; # of object methods close by<br />
<br />
&nbsp; &nbsp; &nbsp; given self { .baz; } <br />
<br />
&nbsp; &nbsp; &nbsp; # this is the same as above but it's<br />
&nbsp; &nbsp; &nbsp; # not scoped. &nbsp;Good for short methods<br />
<br />
&nbsp; &nbsp; &nbsp; $_ = self;<br />
&nbsp; &nbsp; &nbsp; .baz;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; # not really recommended as it<br />
&nbsp; &nbsp; &nbsp; # doesn't seem to be for anything<br />
&nbsp; &nbsp; &nbsp; # but attributes.<br />
&nbsp; &nbsp; &nbsp; $.baz;<br />
&nbsp; &nbsp;}<br />
<br />
&nbsp; &nbsp;method baz {<br />
&nbsp; &nbsp; &nbsp; say 'baz';<br />
&nbsp; &nbsp;}<br />
}<br />
<br />
my $a = A.new;<br />
A::foo;<br />
#A::bar; # dies<br />
<br />
#$a.foo; # dies<br />
$a.bar;<br />
A.bar;<br />
# note: there may be a distinction between<br />
# class and instance methods, but for now<br />
# you use the same method for both</div></td></tr></tbody></table></div>
<p>I also asked Patrick if he thought that Perl 5 in Perl 6 would really happen and if so how.  He said it would happen, but probably not soon.  There are really three options.  The first is to embed Perl 5 in Parrot.  This is really the &#8220;best&#8221; option as it would have 100% compatibility (except weird XS stuff,) and I think Patrick said that it had been prototyped, so that&#8217;s encouraging.  The next option would be to reimplement most of Perl 5 in Perl 6.  This would never get close to 100% but it would still be an option.  The last option would be to have major parts of CPAN reimplemented in Perl 6, thus making compatibility far less important.  Important CPAN modules would be DBI, a good templating system, a web framework (<a href="http://use.perl.org/~masak/journal/38973">in progress</a>), and some form of GUI toolkit.</p>
<p>Somehow we got into a discussion about Mojo, the framework Graham uses at $work.  It is modeled after Rails and is supposed to be simple to port to Perl 6.  The most important thing about it, as far as I can tell, is that it has <strong>no dependencies</strong>.  Graham made it sound like a lightweight framework, but I guess he just meant the no deps thing.  CGI-Application (what I use) totals to 7k lines.  Mojo, on the other hand, totals to 50k.  Not <em>exactly</em> lightweight, but low dependencies is an interesting goal.</p>
<p>And then two thirds of us are going to YAPC::NA, so we talked about that some.  Very exciting things coming up!</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/940" rel="bookmark" class="crp_title">July 2009, DFW.p6m</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/809" rel="bookmark" class="crp_title">Dallas.p6m: June</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1063" rel="bookmark" class="crp_title">Dallas.p6m: August 2009</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/633" rel="bookmark" class="crp_title">Future Perl</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1072" rel="bookmark" class="crp_title">Perl 6 in Perl 5 FOR THE WIN</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/706/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I want from the Perl 5 support policy</title>
		<link>http://blog.afoolishmanifesto.com/archives/707</link>
		<comments>http://blog.afoolishmanifesto.com/archives/707#comments</comments>
		<pubDate>Thu, 14 May 2009 04:33:40 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[support policy]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=707</guid>
		<description><![CDATA[This is in response to chromatic&#8217;s post Writing Perl 5&#8242;s Support Policy I want to be able to use the support policy as a reason to convince customers with lots of Perl installs that they need to update. A big part of this means an easy upgrade. Probably most of the people using Perl 5 [...]]]></description>
			<content:encoded><![CDATA[<p>This is in response to chromatic&#8217;s post <a href="http://www.modernperlbooks.com/mt/2009/05/writing-perl-5s-support-policy.html">Writing Perl 5&#8242;s Support Policy</a></p>
<p>I want to be able to use the support policy as a reason to convince customers with lots of Perl installs that they need to update.  A big part of this means an <strong>easy upgrade</strong>.</p>
<p>Probably most of the people using Perl 5 are in Unix.  That makes it easier for you folks.  On Windows installing Perl is no simple task, either ActivePerl <strong>or</strong> Strawberry Perl.</p>
<p>For example, at $work we use Apache/mod_perl.  <em>(I don&#8217;t wanna hear your &#8220;FastCGI! FastCGI! FastCGI!&#8221;, none of you people have actually helped me so far!)</em>  Let&#8217;s say I want to use the shiny new Perl 5.11.  I install it.  Awesome.  Wait!  mod_perl doesn&#8217;t work!  Ok, reinstall that.  Oh wait!  All of my XS/compiled modules don&#8217;t work!  etc etc.  I understand the fact that Windows is a second class citizen here, but in Unix you probably have the same issue.  You just made some kind of package to install it all at once or something.  That&#8217;s great, but does it help me?  Is updating really supported?</p>
<p>On a side note a point that my boss made when we discussed this issue is the fact that the community may not support Perl 5.8 in the future, but if companies will pay for it, ActiveState will probably support it.  This is good for the customers and helps the community, so I&#8217;d say that&#8217;s really a win-win.</p>
<p>Anyway, those are my thoughts.  Take &#8216;em or leave &#8216;em.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/402" rel="bookmark" class="crp_title">mod_perl: For Your Health!</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1303" rel="bookmark" class="crp_title">The Rise and Fall of mod_perl</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/64" rel="bookmark" class="crp_title">Using &#8220;Rails&#8221; wisdom in Perl</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1331" rel="bookmark" class="crp_title">How CPAN (and Open Source) works</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/986" rel="bookmark" class="crp_title">REST REST REST REST REST</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/707/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Profilers or more specifically NYTProf</title>
		<link>http://blog.afoolishmanifesto.com/archives/635</link>
		<comments>http://blog.afoolishmanifesto.com/archives/635#comments</comments>
		<pubDate>Tue, 12 May 2009 22:36:56 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[nytprof]]></category>
		<category><![CDATA[profiler]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=635</guid>
		<description><![CDATA[At work one of our customers is having us revamp one of the major sections of the site. We are moving in the &#8220;Web Application&#8221; direction; that is, very little HTML, and almost all Javascript. The section of the site that my coworker was working on recently does a lot of calculation. On the old [...]]]></description>
			<content:encoded><![CDATA[<p>At work one of our <a href="http://www.epmsonline.com/">customers</a> is having us revamp one of the major sections of the site.  We are moving in the &#8220;Web Application&#8221; direction; that is, very little HTML, and almost all Javascript.  The section of the site that my coworker was working on recently does a lot of calculation.  On the old HTML page a customer would log in, ask for a certain report, and I guess go get a cup of coffee.  The report took something like five minutes to run; not impossibly long, but long enough that you don&#8217;t want to leave it like that and turn the output into JSON.</p>
<p>So we took a look at the module that does the calculation.  First off, it was a little long (four thousand lines,) so just eyeballing it wouldn&#8217;t easily point us to what was causing the slowdown.  Fortunately my coworker Neil, who wrote the module, had also written a simple to execute perl script, as opposed to everything being in a cgi script.  So with that in hand, we fired up <a href="http://search.cpan.org/perldoc?Devel::NYTProf">NYTProf</a>.</p>
<p>NYTProf is a profiler that was written for use at the (wait for it) New York Times.  After installation using it was extremely easy:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">perl -d:NYTProf calc.pl</div></td></tr></tbody></table></div>
<p>That generates a database of what went down.  Next we ran:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">nytprofhtml</div></td></tr></tbody></table></div>
<p>Which turned everything into nicely formatted html files.  It creates profiles for all of the files used and has some nice javascript sorting built in to the tables etc.  It showed us that we were calling a certain heavyweight function more than we should have (DBI::st::execute <img src='http://blog.afoolishmanifesto.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .)  And then there were other things that we did (simple caching for example: <em>if (!$self->{foo}) { $self->{foo} = &#8230;;} return $self->{foo}</em>) which sped things up something like 70% in the profile.</p>
<p>Anyway, if you find yourself hitting a speed wall, NYTProf isn&#8217;t hard to use at all.  The only problem you may run into is not having a simple to run test script.  This is another reason to split business logic into modules; you can easily use the modules in your controllers, test scripts, and profilers.</p>
<p>Have fun!</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/402" rel="bookmark" class="crp_title">mod_perl: For Your Health!</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/418" rel="bookmark" class="crp_title">Ghetto: Your Solution for Workarounds™</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1196" rel="bookmark" class="crp_title">Missing In Action</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/939" rel="bookmark" class="crp_title">Speed, OO, Black Magic, and YAGNI + RTFM</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1303" rel="bookmark" class="crp_title">The Rise and Fall of mod_perl</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/635/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friday Refactor</title>
		<link>http://blog.afoolishmanifesto.com/archives/693</link>
		<comments>http://blog.afoolishmanifesto.com/archives/693#comments</comments>
		<pubDate>Sat, 09 May 2009 06:42:19 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=693</guid>
		<description><![CDATA[It&#8217;s Friday, so a long post is not in order. With that in mind, a simple refactor for your pattern matching skulls and skills: before: 123456789101112131415&#160; &#160;my @files = File::Find::Rule-&#62;file&#40;&#41;-&#62;name&#40;'*.t'&#41; &#160; &#160; &#160; -&#62;maxdepth&#40; 1 &#41;-&#62;in&#40; &#160; &#160; &#160; &#160; &#160;File::Spec-&#62;catdir&#40; &#160; &#160; &#160; &#160; &#160; &#160; $self-&#62;get_directory, 't' &#160; &#160; &#160; &#41; &#41;; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s Friday, so a long post is <strong>not</strong> in order.  With that in mind, a simple refactor for your pattern matching skulls and skills:</p>
<p>before:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@files</span> <span style="color: #339933;">=</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Find</span><span style="color: #339933;">::</span><span style="color: #006600;">Rule</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">file</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'*.t'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #006600;">maxdepth</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">in</span><span style="color: #009900;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File<span style="color: #339933;">::</span><span style="color: #006600;">Spec</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">catdir</span><span style="color: #009900;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_directory</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'t'</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@total_results</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; &nbsp;<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@files</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@total_results</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">&quot;&lt;span class='file'&gt;$file&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@total_results</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">test</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$file</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&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/join.html"><span style="color: #000066;">join</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@total_results</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Do you see what I see?  We&#8217;re iterating over a list and generating a new list&#8230;  And then we are just doing a join on that.  Enjoy the nice and functional rewrite.</p>
<p>after:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&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/join.html"><span style="color: #000066;">join</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <a href="http://perldoc.perl.org/functions/map.html"><span style="color: #000066;">map</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;&lt;span class='file'&gt;$_&lt;/span&gt;&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">test</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$_</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Find</span><span style="color: #339933;">::</span><span style="color: #006600;">Rule</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">file</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'*.t'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">-&gt;</span><span style="color: #006600;">maxdepth</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">in</span><span style="color: #009900;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File<span style="color: #339933;">::</span><span style="color: #006600;">Spec</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">catdir</span><span style="color: #009900;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get_directory</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'t'</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/764" rel="bookmark" class="crp_title">Script to Rename MP3&#8242;s</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/586" rel="bookmark" class="crp_title">Perl::Tidy: annoying facts</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/562" rel="bookmark" class="crp_title">More Tools Monday</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1113" rel="bookmark" class="crp_title">Turns out there really are Computer Gremlins!</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/482" rel="bookmark" class="crp_title">Implementing map with Perl 6 and Perl 6</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/693/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making MSDOS a little bit nicer</title>
		<link>http://blog.afoolishmanifesto.com/archives/669</link>
		<comments>http://blog.afoolishmanifesto.com/archives/669#comments</comments>
		<pubDate>Fri, 08 May 2009 01:01:10 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/?p=669</guid>
		<description><![CDATA[I work at a Microsoft Company more or less. We use SQL Server, IIS (moving to Apache&#8230;), and various flavors of Windows for all of our machines. I haven&#8217;t had the cojones to install Ubunutu on my desktop yet, so I am stuck with cygwin and friends. But the perl that runs my server is [...]]]></description>
			<content:encoded><![CDATA[<p>I work at a <a href="http://www.mitsi.com/">Microsoft Company</a> more or less.  We use SQL Server, IIS (moving to Apache&#8230;), and various flavors of Windows for all of our machines.  I haven&#8217;t had the cojones to install Ubunutu on my desktop yet, so I am stuck with cygwin and friends.  But the perl that runs my server is <strong>not</strong> in cygwin.  That means that if I want to do valid testing I have to do it with the regular perl.  I&#8217;ve tried running <strong>prove</strong> from the cygwin commandline, (ie, /cygdrive/c/usr/bin/perl/prove,) but it just hangs.  So I just have to suck it up and run prove from cmd.</p>
<p>The color highlighting doesn&#8217;t work (or at least I couldn&#8217;t get it to) so with code that sometimes throws a lot of warnings (that&#8217;s intentional, I am testing croaks often) I see way too much noise to follow what&#8217;s going on.  Redirection to the rescue!  Instead of just running <strong>prove</strong>, I can run</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">prove 2&gt; foo</div></td></tr></tbody></table></div>
<p>instead and it redirects all of the warnings to the file foo.  Although it&#8217;s obvious, it makes running tests that much easier, and I think running tests should really be the path of least resistance.  So thank you DOS makers, for implementing STDERR redirection, I didn&#8217;t think you&#8217;d have done that, but you did.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://blog.afoolishmanifesto.com/archives/629" rel="bookmark" class="crp_title">WebCritic: standalone version</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/596" rel="bookmark" class="crp_title">PerlCritic for Web Developers</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1303" rel="bookmark" class="crp_title">The Rise and Fall of mod_perl</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1118" rel="bookmark" class="crp_title">&#8220;Turns out there really are Computer Gremlins!&#8221; redux</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1140" rel="bookmark" class="crp_title">Moose Test Refactoring</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.afoolishmanifesto.com/archives/669/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
