<?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; Ruby</title>
	<atom:link href="http://blog.afoolishmanifesto.com/archives/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.afoolishmanifesto.com</link>
	<description>fREWdiculous!</description>
	<lastBuildDate>Sat, 28 Jan 2012 17:34:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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[perl]]></category>
		<category><![CDATA[Ruby]]></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: #000000; font-weight: bold;">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/1515" rel="bookmark" class="crp_title">Screen Scrape for Love with Web::Scraper</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/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>Migrating from IIS to Apache</title>
		<link>http://blog.afoolishmanifesto.com/archives/59</link>
		<comments>http://blog.afoolishmanifesto.com/archives/59#comments</comments>
		<pubDate>Wed, 17 Dec 2008 23:00:13 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/archives/59</guid>
		<description><![CDATA[At my job we use a combination of IIS, SQL Server, and Perl. In general it works pretty well. But there is one major problem: if we ever do a warn in perl, instead of printing the message to the log, it crashes the server. That&#8217;s a big deal since multiple people are using the [...]]]></description>
			<content:encoded><![CDATA[<p>At my job we use a combination of IIS, SQL Server, and Perl.  In general it works pretty well.  But there is one major problem: if we ever do a warn in perl, instead of printing the message to the log, it crashes the server.  That&#8217;s a big deal since multiple people are using the server and fixing the issue means VNCing in and recycling the app pool.  This doesn&#8217;t always happen, but it happens a lot; enough to make me consider setting up Apache on my personal computer so that I can get some serious logging.  Anyway, I don&#8217;t know if we have a typical setup or not, but this is what I had to do to get it all going.</p>
<ol>
<li><strong>Install ActiveState perl into C:/usr</strong> (not C:/Perl.)  You can get the latest version <a href="http://www.activestate.com/Products/activeperl/index.mhtml">here</a>.  That&#8217;s more or less it for installing perl.  Note: Latest at the time of writing is Perl 5.10.0.1004</li>
<li><strong>Install Apache.</strong>  You can get the latest version <a href="http://httpd.apache.org/download.cgi">here</a>.  I suggest getting the binary msi.  Get the one with OpenSSL if you want to set up https (not covered here.) Note: Latest at the time of writing is Apache 2.2.10 (OpenSSL 0.9.8i).</li>
<li><strong>Install Perl Modules.</strong>  I am not sure of what all modules our software requires that doesn&#8217;t come with perl out of the box, but I know for sure that we need DateTime.  So to install that open a console and type <em>ppm install DateTime</em>.  You can use the gui instead if you&#8217;d like, but it tends to just get in my way because it&#8217;s so slow.  The way you will know that you are missing a module is if you get an error in the log like this:
<div class="codecolorer-container qbasic 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 /></div></td><td><div class="qbasic codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#91;</span>Tue Nov <span style="color: #cc66cc;">18</span> <span style="color: #cc66cc;">17</span>:<span style="color: #cc66cc;">33</span>:05 <span style="color: #cc66cc;">2008</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><a href="http://www.qbasicnews.com/qboho/qckerror.shtml"><span style="color: #000066;">ERROR</span></a><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>client 127.0.0.1<span style="color: #66cc66;">&#93;</span> Premature <a href="http://www.qbasicnews.com/qboho/qckend.shtml"><span style="color: #000066;">END</span></a> of script headers: foo.plx<span style="color: #66cc66;">,</span> referer: http:<span style="color: #66cc66;">//</span>127.0.0.1<span style="color: #66cc66;">/</span><br />
<span style="color: #66cc66;">&#91;</span>Tue Nov <span style="color: #cc66cc;">18</span> <span style="color: #cc66cc;">17</span>:<span style="color: #cc66cc;">33</span>:05 <span style="color: #cc66cc;">2008</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><a href="http://www.qbasicnews.com/qboho/qckerror.shtml"><span style="color: #000066;">ERROR</span></a><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>client 127.0.0.1<span style="color: #66cc66;">&#93;</span> Can<span style="color: #808080;">'t locate DateTime.pm in @INC (@INC contains: C:/usr/site/lib C:/usr/lib .) at foo.plx line 39., referer: http://127.0.0.1/</span><br />
<span style="color: #66cc66;">&#91;</span>Tue Nov <span style="color: #cc66cc;">18</span> <span style="color: #cc66cc;">17</span>:<span style="color: #cc66cc;">33</span>:05 <span style="color: #cc66cc;">2008</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><a href="http://www.qbasicnews.com/qboho/qckerror.shtml"><span style="color: #000066;">ERROR</span></a><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>client 127.0.0.1<span style="color: #66cc66;">&#93;</span> BEGIN failed<span style="color: #66cc66;">--</span>compilation aborted at foo.plx <a href="http://www.qbasicnews.com/qboho/qckline.shtml"><span style="color: #000066;">LINE</span></a> <span style="color: #cc66cc;">39</span>.<span style="color: #66cc66;">,</span> referer: http:<span style="color: #66cc66;">//</span>127.0.0.1<span style="color: #66cc66;">/</span></div></td></tr></tbody></table></div>
<li><strong>Migrate source code.</strong>  For me this just meant checking out one folder from subversion into C:/Inetpub (recommended so that things will continue to work with IIS and apache,) and copying a directory of static html into the same directory.  I ended up with two main directories like this: C:/Inetpub/main and C:/Inetput/static.  (Names changed to protect the innocent <img src='http://blog.afoolishmanifesto.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</li>
<li><strong>Configure Apache.</strong>  This, besides the last step, is probably the hardest step.  First open httpd.conf, probably C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf&#8230; but you can find it in the start menu).  On IIS our static directory is the root and then the main directory is a subdirectory of the static directory.  To set this up, first find the
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;...&quot;</span></div></td></tr></tbody></table></div>
<p>directive in the httpd.conf and change it to</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;C:/Inetpub/static&quot;</span></div></td></tr></tbody></table></div>
<p>Next you&#8217;ll want to make sure that your Directories are configured.  Find the existing Directory section and just change the directory to whatever you just did, and then add another one for each other directory in Inetpub.  This is what I ended up with:</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;C:/Inetpub/static&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> ExecCGI<br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;C:/Inetpub/main&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> ExecCGI<br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;</div></td></tr></tbody></table></div>
<p>And then because our static directory was root and the main directory was a subdirectory of the static directory, add a line like the following to the alias_module section:</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">Alias</span> /<span style="color: #00007f;">user</span> /Inetpub/main</div></td></tr></tbody></table></div>
<p>Also, since we are a perl shop, we have to allow execution of various types of perl programs, so find the mime_module section of the code and make the AddHandler part look like this:</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">AddHandler</span> cgi-<span style="color: #00007f;">script</span> .cgi .plx .plex</div></td></tr></tbody></table></div>
<p>And then last of all, the main page of our root directory on IIS is Default.html, so instead of renaming it to index.html, find the secion of the code for the Directory and add a DirectoryIndex part so it is like this:</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">DirectoryIndex</span> Default.html</div></td></tr></tbody></table></div>
<p>I ended up setting it for both main and static.  Here&#8217;s my entire httpd.conf if you just wanna see the final product:</p>
<div class="codecolorer-container apache 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 />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">ServerRoot</span> <span style="color: #7f007f;">&quot;C:/Program Files/Apache Software Foundation/Apache2.2&quot;</span><br />
<span style="color: #00007f;">Listen</span> <span style="color: #ff0000;">80</span><br />
<span style="color: #00007f;">LoadModule</span> actions_module modules/mod_actions.so<br />
<span style="color: #00007f;">LoadModule</span> alias_module modules/mod_alias.so<br />
<span style="color: #00007f;">LoadModule</span> asis_module modules/mod_asis.so<br />
<span style="color: #00007f;">LoadModule</span> auth_basic_module modules/mod_auth_basic.so<br />
<span style="color: #00007f;">LoadModule</span> authn_default_module modules/mod_authn_default.so<br />
<span style="color: #00007f;">LoadModule</span> authn_file_module modules/mod_authn_file.so<br />
<span style="color: #00007f;">LoadModule</span> authz_default_module modules/mod_authz_default.so<br />
<span style="color: #00007f;">LoadModule</span> authz_groupfile_module modules/mod_authz_groupfile.so<br />
<span style="color: #00007f;">LoadModule</span> authz_host_module modules/mod_authz_host.so<br />
<span style="color: #00007f;">LoadModule</span> authz_user_module modules/mod_authz_user.so<br />
<span style="color: #00007f;">LoadModule</span> autoindex_module modules/mod_autoindex.so<br />
<span style="color: #00007f;">LoadModule</span> cgi_module modules/mod_cgi.so<br />
<span style="color: #00007f;">LoadModule</span> dir_module modules/mod_dir.so<br />
<span style="color: #00007f;">LoadModule</span> env_module modules/mod_env.so<br />
<span style="color: #00007f;">LoadModule</span> include_module modules/mod_include.so<br />
<span style="color: #00007f;">LoadModule</span> isapi_module modules/mod_isapi.so<br />
<span style="color: #00007f;">LoadModule</span> log_config_module modules/mod_log_config.so<br />
<span style="color: #00007f;">LoadModule</span> mime_module modules/mod_mime.so<br />
<span style="color: #00007f;">LoadModule</span> negotiation_module modules/mod_negotiation.so<br />
<span style="color: #00007f;">LoadModule</span> setenvif_module modules/mod_setenvif.so<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> !mpm_netware_module&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> !mpm_winnt_module&gt;<br />
<span style="color: #00007f;">User</span> daemon<br />
<span style="color: #00007f;">Group</span> daemon<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
<span style="color: #00007f;">ServerAdmin</span> frewmbot@gmail.com<br />
<span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;C:/Inetpub/static&quot;</span><br />
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> /&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">FollowSymLinks</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">deny</span>,<span style="color: #00007f;">allow</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Deny</span> from <span style="color: #0000ff;">all</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;C:/Inetpub/static&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> ExecCGI<br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">DirectoryIndex</span> Default.html<br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;C:/Inetpub/main&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> ExecCGI<br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">DirectoryIndex</span> main.plx<br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> dir_module&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">DirectoryIndex</span> index.html<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;^.ht&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Deny</span> from <span style="color: #0000ff;">all</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Satisfy</span> <span style="color: #0000ff;">All</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;<br />
<span style="color: #00007f;">ErrorLog</span> <span style="color: #7f007f;">&quot;logs/error.log&quot;</span><br />
<span style="color: #00007f;">LogLevel</span> warn<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> log_config_module&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">LogFormat</span> <span style="color: #7f007f;">&quot;%h %l %u %t &quot;</span>%r<span style="color: #7f007f;">&quot; %&gt;s %b &quot;</span>%{Referer}i<span style="color: #7f007f;">&quot; &quot;</span>%{User-Agent}i<span style="color: #7f007f;">&quot;&quot;</span> combined<br />
&nbsp; &nbsp; <span style="color: #00007f;">LogFormat</span> <span style="color: #7f007f;">&quot;%h %l %u %t &quot;</span>%r<span style="color: #7f007f;">&quot; %&gt;s %b&quot;</span> common<br />
&nbsp; &nbsp; &lt;<span style="color: #000000; font-weight:bold;">IfModule</span> logio_module&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">LogFormat</span> <span style="color: #7f007f;">&quot;%h %l %u %t &quot;</span>%r<span style="color: #7f007f;">&quot; %&gt;s %b &quot;</span>%{Referer}i<span style="color: #7f007f;">&quot; &quot;</span>%{User-Agent}i<span style="color: #7f007f;">&quot; %I %O&quot;</span> combinedio<br />
&nbsp; &nbsp; &lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">CustomLog</span> <span style="color: #7f007f;">&quot;logs/access.log&quot;</span> common<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> alias_module&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">Alias</span> /<span style="color: #00007f;">user</span> /Inetpub/main<br />
&nbsp; &nbsp; <span style="color: #00007f;">ScriptAlias</span> /cgi-bin/ <span style="color: #7f007f;">&quot;C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/&quot;</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;<br />
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin&quot;</span>&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">None</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span><br />
&nbsp; &nbsp; <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span><br />
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;<br />
<span style="color: #00007f;">DefaultType</span> text/plain<br />
&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mime_module&gt;<br />
&nbsp; &nbsp; <span style="color: #00007f;">TypesConfig</span> conf/mime.types<br />
&nbsp; &nbsp; <span style="color: #00007f;">AddType</span> application/<span style="color: #0000ff;">x-compress</span> .Z<br />
&nbsp; &nbsp; <span style="color: #00007f;">AddType</span> application/<span style="color: #0000ff;">x-gzip</span> .gz .tgz<br />
&nbsp; &nbsp; <span style="color: #00007f;">AddHandler</span> cgi-<span style="color: #00007f;">script</span> .cgi .plx .plex<br />
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</div></td></tr></tbody></table></div>
</li>
<li>Ensure all of your <strong>perl files start with #!/usr/bin/perl.</strong>  If you don&#8217;t do this Apache will give you an error, 500 Internal Server on the output, and then something like this in the log:
<div class="codecolorer-container apache 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 /></div></td><td><div class="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[Tue Dec 09 <span style="color: #ff0000;">20</span>:<span style="color: #ff0000;">59</span>:04 <span style="color: #ff0000;">2008</span>] [error] [client 127.0.0.1] (OS <span style="color: #ff0000;">3</span>)The system cannot find the path specified. &nbsp;: couldn<span style="color: #7f007f;">'t create child process: 720003: employee_training_report.plx<br />
[Tue Dec 09 20:59:04 2008] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified. &nbsp;: couldn'</span>t spawn child process: C:/Inetpub/epms/customer/employee_training_report.plx</div></td></tr></tbody></table></div>
<p>As stated, this just means that the bangline is wrong and needs to be set to #!/usr/bin/perl.  Note: the log is probably in C:/Program Files/Apache Software Foundation/Apache2.2/logs/error.log, but again, you can find that in the start menu.</li>
<li><strong>Fix all headers.</strong>  Usually with IIS we output headers like this:
<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 /></div></td><td><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;HTTP/1.0 200 OK<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> header<span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>header is a function of the CGI module.  For IIS you print out the first part to force the server into NPH mode.  I recommend, for ease of migration, making your own module that your scripts can use that will print the header correctly whether it&#8217;s Apache or IIS.  Here&#8217;s ours:</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 /></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> header <span style="color: #009900;">&#123;</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><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ENV</span><span style="color: #009900;">&#123;</span>PERLXS<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span><span style="color: #ff0000;">&quot;HTTP/1.0 200 OK<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">:</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>CGI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@_</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;</span>br <span style="color: #339933;">/&gt;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>And note that anything that gets passed to the header method automatically takes any arguments that you passed and gives them to CGI.  This allows for a simple method of regular expression based search and replace to fix things to use your new method. (for vim something like this will work: :%s/v^(s*prints+).*header((.*));/1Module::header2;/g )</p>
<p>I do this part as I see it as a problem, as my boss didn&#8217;t want me to search and replace the whole codebase, so the error you are going to look for is a 500 from the browser and then something like this in the log:</p>
<div class="codecolorer-container apache 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="apache codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[Tue Nov <span style="color: #ff0000;">18</span> <span style="color: #ff0000;">17</span>:<span style="color: #ff0000;">38</span>:<span style="color: #ff0000;">38</span> <span style="color: #ff0000;">2008</span>] [error] [client 127.0.0.1] malformed <span style="color: #00007f;">header</span> from <span style="color: #00007f;">script</span>. Bad <span style="color: #00007f;">header</span>=HTTP/<span style="color: #ff0000;">1.0</span> <span style="color: #ff0000;">200</span> OK: foo.plx</div></td></tr></tbody></table></div>
</li>
</ol>
<p>And that&#8217;s basically it!  Any tips you might have to add are welcome!</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><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/402" rel="bookmark" class="crp_title">mod_perl: For Your Health!</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/629" rel="bookmark" class="crp_title">WebCritic: standalone version</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/59/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby 1.9 is out!</title>
		<link>http://blog.afoolishmanifesto.com/archives/49</link>
		<comments>http://blog.afoolishmanifesto.com/archives/49#comments</comments>
		<pubDate>Wed, 26 Dec 2007 18:54:54 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby1.9]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/archives/49</guid>
		<description><![CDATA[Exciting! It was apparently put up yesterday, on Christmas. What a cool gift right? I looked through the changed maintained my Mauricio and here are /my/ favorites. *New literal hash syntax [Ruby2]* 1&#123;a: &#34;foo&#34;&#125;&#160; &#160; &#160; # =&#62; {:a=&#62;&#34;foo&#34;} *.() and calling Procs without #call/#[] [EXPERIMENTAL]* You can now do: 1a = lambda{&#124;*b&#124; b} a.(1,2) [...]]]></description>
			<content:encoded><![CDATA[<p>Exciting!  It was apparently put up yesterday, on Christmas.  What a cool gift right?  I looked through the <a href="http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9">changed maintained my Mauricio</a> and here are /my/ favorites.</p>
<p>*New literal hash syntax [Ruby2]*</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 /></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:#006600; font-weight:bold;">&#123;</span>a: <span style="color:#996600;">&quot;foo&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; {:a=&gt;&quot;foo&quot;}</span></div></td></tr></tbody></table></div>
<p>*.() and calling Procs without #call/#[] [EXPERIMENTAL]*</p>
<p>You can now do:</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">a = lambda{|*b| b} a.(1,2) # =&gt; [1, 2]</div></td></tr></tbody></table></div>
<p>*Multiple splats allowed*</p>
<p>1.9 allows multiple splat operators when calling a method:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">def</span> foo<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>a<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;a<br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp;foo<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006666;">4</span>, <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">5</span>,<span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [1, 2, 3, 4, 5, 6]</span></div></td></tr></tbody></table></div>
<p>*Mandatory arguments after optional arguments allowed*</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">def</span> m<span style="color:#006600; font-weight:bold;">&#40;</span>a, b=<span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#006600; font-weight:bold;">*</span>c, d<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>a,b,c,d<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp;m<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; [1, nil, [], 2]</span></div></td></tr></tbody></table></div>
<p>*Object#tap*</p>
<p>Passes the object to the block and returns it (meant to be used for call chaining).</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">&quot;F&quot;.tap{|x| x.upcase!}[0] # =&gt; &quot;F&quot; # Note that &quot;F&quot;.upcase![0] would fail since upcase! would return nil in this # case.</div></td></tr></tbody></table></div>
<p>*Module#attr is an alias of attr_reader*</p>
<p>Use</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">attr <span style="color:#ff3333; font-weight:bold;">:foo</span>=</div></td></tr></tbody></table></div>
<p>to create a read/write accessor. (RCR#331)</p>
<p>*Enumerable#cycle*</p>
<p>Calls the given block for each element of the enumerable in a never-ending cycle:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;a&quot;</span>, <span style="color:#996600;">&quot;b&quot;</span>, <span style="color:#996600;">&quot;c&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
a.<span style="color:#9900CC;">cycle</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> x <span style="color:#006600; font-weight:bold;">&#125;</span> &nbsp;<span style="color:#008000; font-style:italic;"># print, a, b, c, a, b, c,.. forever.</span></div></td></tr></tbody></table></div>
<p>*Enumerable#group_by*</p>
<p>Groups the values in the enumerable according to the value returned by the block:</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 /></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:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">group_by</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> x <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># =&gt; {0=&gt;[3, 6, 9], 1=&gt;[1, 4, 7, 10], 2=&gt;[2, 5, 8]}</span></div></td></tr></tbody></table></div>
<p>*Enumerable#drop*</p>
<p>Without a block, returns an array with all but the first n elements from the enumeration. Otherwise drops elements while the block returns true (and returns all the elements after it returns a false value):</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span> a.<span style="color:#9900CC;">drop</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; [4, 5] </span><br />
a.<span style="color:#9900CC;">drop</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> i <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">3</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># =&gt; [3, 4, 5]</span></div></td></tr></tbody></table></div>
<p>*Enumerable#inject (#reduce) without a block*</p>
<p>If no block is given, the first argument to #inject is the name of a two-argument method that will be called; the optional second argument is the initial value:</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 /></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:#006600; font-weight:bold;">&#91;</span>RUBY_VERSION, RUBY_RELEASE_DATE<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># =&gt; [&quot;1.9.0&quot;, &quot;2007-08-03&quot;] (1..10).reduce(:+) # =&gt; 55</span></div></td></tr></tbody></table></div>
<p>*Enumerable#count*</p>
<p>It could be defined in Ruby as</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 /></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:#9966CC; font-weight:bold;">def</span> count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>a<span style="color:#006600; font-weight:bold;">&#41;</span> inject<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</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>c, e<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#9966CC; font-weight:bold;">if</span> a.<span style="color:#9900CC;">size</span> == <span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;"># suspect, but this is how it works (a[0] == e) ? c + 1 : c else yield(e) ? c + 1 : c end end end</span></div></td></tr></tbody></table></div>
<p>Therefore</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 /></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:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;bar&quot;</span>, <span style="color:#006666;">1</span>, <span style="color:#996600;">&quot;foo&quot;</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">count</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; 1 [&quot;bar&quot;, 1, &quot;foo&quot;, 2].count{|x| x.to_i != 0} # =&gt; 2</span></div></td></tr></tbody></table></div>
<p>*Array#nitems*</p>
<p>It is equivalent to selecting the elements that satisfy a condition and obtaining the size of the resulting array:</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 /></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:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span> <span style="color:#006666;">2</span> <span style="color:#006666;">3</span> <span style="color:#006666;">4</span> <span style="color:#006666;">5</span> <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">nitems</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> x.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span>&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; 3</span></div></td></tr></tbody></table></div>
<p>*Block argument to Array#index, Array#rindex [Ruby2]*</p>
<p>They can now take a block to make them work like #select.</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 /></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:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'a'</span>,<span style="color:#996600;">'b'</span>,<span style="color:#996600;">'c'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">index</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e == <span style="color:#996600;">'b'</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># =&gt; 1 ['a','b','c'].index{|e| e == 'c'} # =&gt; 2 ['a','a','a'].rindex{|e| e == 'a'} # =&gt; 2 ['a','a','a'].index{|e| e == 'b'} # =&gt; nil</span></div></td></tr></tbody></table></div>
<p>*Array#combination*</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ary.<span style="color:#9900CC;">combination</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> ...<span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>yields all the combinations of length n of the elements in the array to the given block. If no block is passed, it returns an enumerator instead. The order of the combinations is unspecified.</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#93;</span> a.<span style="color:#9900CC;">combination</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span> <span style="color:#008000; font-style:italic;">#=&gt; [[1],[2],[3],[4]] a.combination(2).to_a #=&gt; [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]] a.combination(3).to_a #=&gt; [[1,2,3],[1,2,4],[1,3,4],[2,3,4]] a.combination(4).to_a #=&gt; [[1,2,3,4]] a.combination(0).to_a #=&gt; [[]]: one combination of length 0 a.combination(5).to_a #=&gt; [] : no combinations of length 5</span></div></td></tr></tbody></table></div>
<p>*Array#permutation*</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Operates like <span style="color:#008000; font-style:italic;">#combination, but with permutations of length n.</span><br />
<span style="color:#006600; font-weight:bold;">&lt;</span>code lang=<span style="color:#996600;">&quot;ruby&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span> a.<span style="color:#9900CC;">permutation</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span> <span style="color:#008000; font-style:italic;">#=&gt; [[1],[2],[3]] a.permutation(2).to_a #=&gt; [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]] a.permutation(3).to_a #=&gt; [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] a.permutation(0).to_a #=&gt; [[]]: one permutation of length 0 a.permutation(4).to_a #=&gt; [] : no permutations of length 4</span></div></td></tr></tbody></table></div>
<p>*Array#pop, Array#shift*</p>
<p>They can take an argument to specify how many objects to return:</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 /></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:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#91;</span>a b c d<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">pop</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; [&quot;c&quot;, &quot;d&quot;]</span></div></td></tr></tbody></table></div>
<p>*Hash preserves order!*</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RUBY_VERSION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; &quot;1.9.0&quot;</span><br />
h=<span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span> &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; {:a=&gt;1, :b=&gt;2, :c=&gt;3, :d=&gt;4}</span><br />
h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:e</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006666;">5</span><br />
h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; {:a=&gt;1, :b=&gt;2, :c=&gt;3, :d=&gt;4, :e=&gt;5}</span><br />
<br />
h.<span style="color:#9900CC;">keys</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [:a, :b, :c, :d, :e]</span><br />
h.<span style="color:#9900CC;">values</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [1, 2, 3, 4, 5]</span><br />
h.<span style="color:#9900CC;">to_a</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [[:a, 1], [:b, 2], [:c, 3], [:d, 4], [:e, 5]]</span></div></td></tr></tbody></table></div>
<p>vs.</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">RUBY_VERSION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; &quot;1.8.6&quot;</span><br />
h=<span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span> &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; {:a=&gt;1, :b=&gt;2, :c=&gt;3, :d=&gt;4}</span><br />
h<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:e</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006666;">5</span><br />
h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; {:e=&gt;5, :a=&gt;1, :b=&gt;2, :c=&gt;3, :d=&gt;4}</span><br />
h.<span style="color:#9900CC;">keys</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [:e, :a, :b, :c, :d]</span><br />
h.<span style="color:#9900CC;">values</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [5, 1, 2, 3, 4]</span><br />
h.<span style="color:#9900CC;">to_a</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; [[:e, 5], [:a, 1], [:b, 2], [:c, 3], [:d, 4]]</span></div></td></tr></tbody></table></div>
<p>*Numeric#upto, #downto, #times, #step*</p>
<p>These methods return an enumerator if no block is given:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006666;">10</span>.<span style="color:#9900CC;">times</span> a.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>s,x<span style="color:#006600; font-weight:bold;">|</span> s<span style="color:#006600; font-weight:bold;">+</span>x <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># =&gt; 45 a = [] b = 10.downto(5) b.each{|x| a &lt;&lt; x} a # =&gt; [10, 9, 8, 7, 6, 5]</span></div></td></tr></tbody></table></div>
<p>*Range#cover?*</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">range.<span style="color:#9900CC;">cover</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>value<span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>compares value to the begin and end values of the range, returning true if it is comprised between them, honoring #exclude_end?.</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 /></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:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;a&quot;</span>..<span style="color:#996600;">&quot;z&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">cover</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;c&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; true</span><br />
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;a&quot;</span>..<span style="color:#996600;">&quot;z&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">cover</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;5&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; false</span></div></td></tr></tbody></table></div>
<p>*Limit input in IO#gets, IO#readline, IO#readlines, IO#each_line, IO#lines, IO.foreach, IO.readlines, StringIO#gets, StringIO#readline, StringIO#each, StringIO#readlines*</p>
<p>These methods accept an optional integer argument to specify the maximum amount of data to be read. The limit is specified either as the (optional) second argument, or by passing a single integer argument (i.e. the first argument is interpreted as the limit if it&#8217;s an integer, as a line separator otherwise).</p>
<p>*IO#ungetc, StringIO#ungetc*</p>
<p>Allows to push back an arbitrarily large character.</p>
<p>*Seven predicate methods where added for the weekdays:*</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 /></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:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; Thu Nov 03 18:58:25 CET 2005</span><br />
<span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">sunday</span>?&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; false</span></div></td></tr></tbody></table></div>
<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/4" rel="bookmark" class="crp_title">Friday Tips and Tricks</a></li><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/770" rel="bookmark" class="crp_title">Web Comic Downloaders</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/1415" rel="bookmark" class="crp_title">Reactions to porting Log::Contextual to 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/49/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Friday Tips and Tricks</title>
		<link>http://blog.afoolishmanifesto.com/archives/4</link>
		<comments>http://blog.afoolishmanifesto.com/archives/4#comments</comments>
		<pubDate>Fri, 06 Jul 2007 23:53:53 +0000</pubDate>
		<dc:creator>fREW Schmidt</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://blog.afoolishmanifesto.com/archives/4</guid>
		<description><![CDATA[Time saving tips and tricks! This first tip is something that I use almost daily. Do you ever want to change a filename to something that is similar to the original name? For instance, maybe you just want to change/add/remove the extension? Well, if you are using a reasonable shell you can do the following: [...]]]></description>
			<content:encoded><![CDATA[<p>Time saving tips and tricks!</p>
<p>This first tip is something that I use almost daily.  Do you ever want to change a filename to something that is similar to the original name?  For instance, maybe you just want to change/add/remove the extension?  Well, if you are using a reasonable shell you can do the following:</p>
<div class="codecolorer-container bash 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 /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># Add .txt to the filename</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> textfiel<span style="color: #7a0874; font-weight: bold;">&#123;</span>,.txt<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<span style="color: #666666; font-style: italic;"># change el to le</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> textfi<span style="color: #7a0874; font-weight: bold;">&#123;</span>el,le<span style="color: #7a0874; font-weight: bold;">&#125;</span>.txt<br />
<span style="color: #666666; font-style: italic;"># remove extension</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> textfile<span style="color: #7a0874; font-weight: bold;">&#123;</span>.txt,<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Or how about this; fairly often I will be programming and I will be adding a predefined string to the end of another string a bunch of times, except for the last time.  The idea is to put the predefined string between some other things.   This is pretty regular if you are generating HTML or SQL. Well, instead of doing the following:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">output = <span style="color:#996600;">&quot;&quot;</span><br />
some_array.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>item,index<span style="color:#006600; font-weight:bold;">|</span><br />
output <span style="color:#006600; font-weight:bold;">+</span>= item<br />
output <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot; AND &quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> index = some_array.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>you can do:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">output = some_array.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; AND &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>Another thing that I find myself doing often is the following:</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">output=<span style="color:#996600;">&quot;&quot;</span><br />
some_array.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>item,index<span style="color:#006600; font-weight:bold;">|</span><br />
output <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot;?&quot;</span><br />
output <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> index=some_array.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>That will generate the question marks for an SQL statement.  Again, that&#8217;s a little messy and there is a cleaner way to do it.</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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">output = some_array.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;?&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;,&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>Much better!  It&#8217;s much shorter and should be easier to understand for other Ruby programmers.</p>
<p>It&#8217;s good to put things like this into practice, because it will make your code more readable and easier to maintain.  Generally, in my manifesto, fewer lines of code (comments and whitespace don&#8217;t count) are better.  Of course, in a language like Ruby this can create performance problems; it&#8217;s a balance between what works for you as the programmer and what works for the user.  If the speed is really an issue, change the code.  Otherwise, save your skull!</p>
<p>If you have any tips for regular things like this, let me know. I need to know stuff like this just as much as anyone else.</p>
<div id="crp_related"><h2>Related Posts:</h2><ul><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/49" rel="bookmark" class="crp_title">Ruby 1.9 is out!</a></li><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/418" rel="bookmark" class="crp_title">Ghetto: Your Solution for Workarounds™</a></li><li><a href="http://blog.afoolishmanifesto.com/archives/63" rel="bookmark" class="crp_title">Ruby style functional programming in 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/4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

