<?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>Aaron Toponce &#187;  &#187; Ruby</title>
	<atom:link href="http://pthree.org/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://pthree.org</link>
	<description>Linux.  GNU.  Freedom.</description>
	<lastBuildDate>Sun, 21 Feb 2010 15:50:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
		<item>
		<title>Poll: First Programming Language?</title>
		<link>http://pthree.org/2007/03/13/poll-first-programming-language/</link>
		<comments>http://pthree.org/2007/03/13/poll-first-programming-language/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 16:47:19 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.pthree.org/2007/03/13/poll-first-programming-language/</guid>
		<description><![CDATA[My coworker asked me this question, and began asking a few others in a couple IRC channels.  So, I thought I&#8217;d extend it to my blog, and the planets that I syndicate.  I added as many choices as I could hoping to see a wide array of votes.  I added a few [...]]]></description>
			<content:encoded><![CDATA[<p>My coworker asked me this question, and began asking a few others in a couple IRC channels.  So, I thought I&#8217;d extend it to my blog, and the planets that I syndicate.  I added as many choices as I could hoping to see a wide array of votes.  I added a few newer languages for the younger audience.</p>
<p>For me, my first language that I sat down and learned in a formal setting was Java.  However, I had TI, Casio, and HP calculators, as well as an Atari 800 that I would fiddle with, and program.  So, Basic was really the first language that I toyed with.  I just never sat down, and took the time to &#8220;learn&#8221; it.</p>
<p>So, for all the programmers, coders, script kiddies and developers out there, what is the 1st programming language that you learned?  If applicable, leave a comment specifying the system that you learned the language on.</p>
<div>
	<div class='democracy'>
		<strong class="poll-question">What was the 1st programming language that you learned?</strong>
		<div class='dem-results'>
		<form action='http://pthree.org/wp-content/plugins/democracy/democracy.php' onsubmit='return dem_Vote(this)'>
		<ul>
			<li>
					<input type='radio' id='dem-choice-19' value='19' name='dem_poll_4' />
					<label for='dem-choice-19'>Basic</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-20' value='20' name='dem_poll_4' />
					<label for='dem-choice-20'>Pascal</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-21' value='21' name='dem_poll_4' />
					<label for='dem-choice-21'>C</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-22' value='22' name='dem_poll_4' />
					<label for='dem-choice-22'>Perl</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-23' value='23' name='dem_poll_4' />
					<label for='dem-choice-23'>Lisp</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-24' value='24' name='dem_poll_4' />
					<label for='dem-choice-24'>Fortran</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-25' value='25' name='dem_poll_4' />
					<label for='dem-choice-25'>Assembly</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-26' value='26' name='dem_poll_4' />
					<label for='dem-choice-26'>PHP</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-27' value='27' name='dem_poll_4' />
					<label for='dem-choice-27'>ASP / ASP.NET</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-28' value='28' name='dem_poll_4' />
					<label for='dem-choice-28'>C++</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-29' value='29' name='dem_poll_4' />
					<label for='dem-choice-29'>Python</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-30' value='30' name='dem_poll_4' />
					<label for='dem-choice-30'>Java</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-31' value='31' name='dem_poll_4' />
					<label for='dem-choice-31'>sh / csh / bash</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-32' value='32' name='dem_poll_4' />
					<label for='dem-choice-32'>Ruby</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-33' value='33' name='dem_poll_4' />
					<label for='dem-choice-33'>Other</label>
			</li>
		</ul>
			<input type='hidden' name='dem_poll_id' value='4' />
			<input type='hidden' name='dem_action' value='vote' />
			<input type='submit' class='dem-vote-button' value='Vote' />
			<a href='/category/ruby/feed/?dem_action=view&amp;dem_poll_id=4' onclick='return dem_getVotes("http://pthree.org/wp-content/plugins/democracy/democracy.php?dem_action=view&amp;dem_poll_id=4", this)' rel='nofollow' class='dem-vote-link'>View Results</a>
		</form>
		</div>
	</div></div>
]]></content:encoded>
			<wfw:commentRss>http://pthree.org/2007/03/13/poll-first-programming-language/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Perl Versus Ruby on CSV</title>
		<link>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/</link>
		<comments>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comments</comments>
		<pubDate>Sat, 30 Dec 2006 02:15:13 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/</guid>
		<description><![CDATA[Ok.  I had a little project at work, at which point, I turned to Perl to accomplish the task.  The project was simple enough: take a comma-separated file, and look at a few fields to see what data is contained.  Based on that data, create a &#8220;weight&#8221;, and assign the weight to [...]]]></description>
			<content:encoded><![CDATA[<p>Ok.  I had a little project at work, at which point, I turned to Perl to accomplish the task.  The project was simple enough: take a comma-separated file, and look at a few fields to see what data is contained.  Based on that data, create a &#8220;weight&#8221;, and assign the weight to the record at the end of the line.</p>
<p>The Perl code I used to accomplish the task is as follows (please take note, that Wordpress loves to parse tags, even if contained within &lt;code&gt; tags.  Wordpress also likes to lowercase the tag, so in Perl, file handles will be in lowercase):</p>
<div class="codecolorer-container perl twitlight" 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 /></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;">#!/usr/bin/perl -w</span><br />
<br />
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>IN<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;UNIVERSE.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>OUT<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;UNIVERSE_WEIGHTED.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #0000ff;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;in&gt;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># &lt;/in&gt; (for Wordpress)</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">@fields</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/,/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">,</span>183<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">182</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\n//</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009966; font-style: italic;">s/\n//</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$counter</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$counter</span> <span style="color: #339933;">==</span> 1<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">print</span> OUT <span style="color: #0000ff;">$_</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;,<span style="color: #000099; font-weight: bold;">\&quot;</span>weight<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_ppp00</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>154<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_ppp04</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>155<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_pri01</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>161<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_pri03</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>163<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_pri05</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>165<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$vtr_pri99</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$fields</span><span style="color: #009900;">&#91;</span>182<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=.</span>5 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_ppp00</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">-=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_ppp04</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>D<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">-=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri01</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>D<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">-=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri03</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>D<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">-=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri05</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>D<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">-=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri99</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>D<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_ppp04</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri01</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri03</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri05</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">+=</span> 1 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vtr_pri99</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>R<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">print</span> OUT <span style="color: #0000ff;">$_</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$weight</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Processed: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$counter</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>IN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>OUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Just for fun, a buddy of mine mentioned to code it in Ruby, and compare results.  Seeing as though I have never coded a Ruby script in my life, I was a bit worried.  However, it wasn&#8217;t too bad.  I just had to cure my itch to put a $ in front of all my variables.  Anyway, heres the Ruby code, following as closely as possible to the Perl code:</p>
<div class="codecolorer-container ruby twitlight" 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 /></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</span><br />
<br />
counter = 0<br />
<br />
outfile = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;UNIVERSE_RUBY.csv&quot;</span>,<span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;UNIVERSE.csv&quot;</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>line<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; counter <span style="color:#006600; font-weight:bold;">+</span>= 1<br />
&nbsp; &nbsp; weight = 0<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>counter == 1<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; outfile <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> line.<span style="color:#CC0066; font-weight:bold;">chop</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,<span style="color:#000099;">\&quot;</span>weight<span style="color:#000099;">\&quot;</span><span style="color:#000099;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; fields = line.<span style="color:#CC0066; font-weight:bold;">chop</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_ppp00 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>154<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_ppp04 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>155<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_pri01 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>161<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_pri03 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>163<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_pri05 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>165<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vtr_pri99 = fields<span style="color:#006600; font-weight:bold;">&#91;</span>182<span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 0.5 <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp00 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">-</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp04 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>D<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">-</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri01 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>D<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">-</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri03 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>D<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">-</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri05 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>D<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">-</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri99 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>D<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp04 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri01 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri03 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri05 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; weight <span style="color:#006600; font-weight:bold;">+</span>= 1 &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri99 == <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span>R<span style="color:#000099;">\&quot;</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; outfile <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> line.<span style="color:#CC0066; font-weight:bold;">chop</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,<span style="color:#000099;">\&quot;</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> weight.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\&quot;</span><span style="color:#000099;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;Processed: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> counter.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\r</span>&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span></div></td></tr></tbody></table></div>
<p>Ok.  As you can see, the code is fairly similar.  The algorithms the same.  Running the script takes a mere second or two, and the file comes out correct.  However, I was curious about execution speed, so I decided to pit one script against the other, time them, and see what happens.  Here are my results</p>
<pre>
aaron@hercules:~/Desktop$ time perl weight.pl
Processed: 5394

real    0m1.386s
user    0m1.304s
sys     0m0.048s
aaron@hercules:~/Desktop$ time ruby weight.rb
Processed: 5394

real    0m2.180s
user    0m1.992s
sys     0m0.124s
</pre>
<p>Am I reading this correctly?  Perl is almost 60% faster at execution with this code than Ruby?  I thought Ruby was supposed to have exceptional file handling.  Better than Perl, even.  However, I have also heard that the Ruby devs are more concerned about functionality than speed, which should be expected.  Still, that&#8217;s a serious speed factor.  If I was worried about speed here, Perl, in this case, would win out.</p>
<p>At any rate, this was a fun little exercise to stretch my scripting muscles, and to learn a bit of Ruby.  I&#8217;m curious if I can make the scripts more efficient.  If you know how, comment below, or <a href="http://www.pthree.org/contact">contact me</a>.</code></p>
]]></content:encoded>
			<wfw:commentRss>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
