<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Talk Like A Duck: Tag perl</title>
    <link>http://talklikeaduck.denhaven2.com/articles/tag/perl</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In Ruby, it's not the dog, it's the tricks!</description>
    <item>
      <title>Danger Will Robinson</title>
      <description>&lt;p&gt;Ruby has a nifty method in kernel called open.  It&amp;#8217;s quite powerful in the way it interprets its first argument, a string telling it what to open.  It can open a file, or it can open a pipe to a sub-process it creates to run a command in that string.  It takes quite a bit of &lt;a href="http://www.ruby-doc.org/core/classes/Kernel.html#M001989&gt;documentation&lt;/a&gt; to describe how that first argument is interpreted.&lt;/p&gt;


	&lt;p&gt;This appears to be one of things which Ruby borrowed/stole from perl.  Perl&amp;#8217;s &lt;a href="http://sunsite.ualberta.ca/Documentation/Misc/perl-5.6.1/pod/perlfunc/open.htmlopen"&gt;open function&lt;/a&gt; has a similar interpretation of it&amp;#8217;s first argument. Again it takes quite a bit of documentation to describe.&lt;/p&gt;


	&lt;p&gt;Which is a cause for concern. Most things that powerful can be misused.&lt;/p&gt;


	&lt;p&gt;I use an application called &lt;a href="http://awstats.sourceforge.net/Awstats"&gt;Awstats&lt;/a&gt; to get statistics on my websites.  Awstats is a very popular application which is written in perl.&lt;/p&gt;


	&lt;p&gt;But I long ago disallowed access to Awstats from the outsite world after I found that my system had been compromised by a bad guy &lt;a href="http://www.idefense.com/intelligence/vulnerabilities/display.php?id=185"&gt;exploiting perl&amp;#8217;s open function.&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Kernel#open, like perl&amp;#8217;s open interprets a path starting with &amp;#8221;|&amp;#8221; as a pipe, and effectively calls IO#popen under the covers, while File#open doesn&amp;#8217;t.&lt;/p&gt;


	&lt;p&gt;This is dangerous if the path argument is coming from a user, say in a web application, because it opens the same security exposure which plagued Awstats, which has had several nasty security bugs because it wasn&amp;#8217;t verifying urls and the nasties were doing things which exploited that like getting it to &amp;#8216;pipe&amp;#8217; to wget to download worms.&lt;/p&gt;


	&lt;p&gt;When I first came across Ruby&amp;#8217;s File#open I was happy to see that IT just treats the name argument as a file path, and chokes if it starts with a &amp;#8221;|&amp;#8221;, and that there was IO#popen which explicitly opens pipes to a command running in a subprocess.&lt;/p&gt;


	&lt;p&gt;I think that it&amp;#8217;s generally better practice in ruby to eschew Kernel#open and use either File#open to open files, and IO#popen to open pipes so that it&amp;#8217;s clear what&amp;#8217;s happening.&lt;/p&gt;


	&lt;p&gt;While the Kernel#open method might be convenient and safe in controlled cases, it seems like it might be the basis of a bad habit when it matters.&lt;/p&gt;</description>
      <pubDate>Thu, 05 Oct 2006 11:23:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:ed94cc5f-09fd-4002-a070-c9de2c3fa7f6</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2006/10/05/danger-will-robinson</link>
      <category>ruby</category>
      <category>perl</category>
      <category>security</category>
      <category>bestpractice</category>
      <trackback:ping>http://talklikeaduck.denhaven2.com/articles/trackback/45</trackback:ping>
    </item>
    <item>
      <title>A Perl of Great Price</title>
      <description>&lt;p&gt;An old programming adage goes: &amp;#8220;You can write Fortran in any language.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Computer languages, like natural languages, tend to spawn their own cultures and &lt;a href="http://en.wikipedia.org/wiki/Parable_of_the_Pearl"&gt;religions&lt;/a&gt;. And it&amp;#8217;s not unexpected that the groups associated with these have &lt;a href="http://en.wikipedia.org/wiki/Pearl_of_Great_Price_%28Mormonism%29"&gt;different slants&lt;/a&gt; on things.&lt;/p&gt;


	&lt;p&gt;One of Ruby&amp;#8217;s strengths is that it stole from the best.  When I look at the language, it feels like Matz took the best features from a variety of languages including Smalltalk, Lisp, and not the least, Perl.&lt;/p&gt;


Two great features which Ruby inherited from Perl are integral support for regular expressions, and Perl&amp;#8217;s excellent statement modifiers which allow things like:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;if&lt;/span&gt; &lt;span class="ident"&gt;test&lt;/span&gt;
   &lt;span class="ident"&gt;statement&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;to be replaced with the more succinct and usually clearer:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;statement&lt;/span&gt; &lt;span class="keyword"&gt;if&lt;/span&gt; &lt;span class="ident"&gt;test&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
However, &lt;span class="caps"&gt;IMHO&lt;/span&gt;, overuse of the Perl features in Ruby can make code &lt;b&gt;too&lt;/b&gt; Perl-like.

	&lt;p&gt;I&amp;#8217;ve seen my share of Ruby code which is hard-to read and understand, and a lot of that looks suspiciously like Perl code re-written in Ruby.&lt;/p&gt;


	&lt;p&gt;A ruby, being a gemstone which is normally cut before being put to use, has facets, unlike a pearl.&lt;/p&gt;


	&lt;p&gt;The facets of Ruby, the language, let indiduals approach it from different directions.  To me, as an old Smalltaker, it tends to look like Smalltalk. I tend to view it with Smalltalk-colored glasses.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m sure that, to a programmer deeply steeped in Perl, Ruby looks like Perl with a cleaned-up view of object-oriented features.&lt;/p&gt;


&lt;h2&gt;Literate Programming&lt;/h2&gt;
I&amp;#8217;ve long been a fan of the goals of &lt;a href="http://www.literateprogramming.com/"&gt;literate programming&lt;/a&gt;. Source code should be viewed as literature, something which communcates to human readers, and not just fodder for a tool chain which produces something which is executable by a machine.
&lt;p/&gt;
&lt;p&gt;I read and write Perl on a level similar to how I converse in French.  I&amp;#8217;m told that I can speak French fairly well, and I can make myself understood.  On the other hand I have a hard time understanding spoken French.&lt;/p&gt;

	&lt;p&gt;Too often, Perl looks to me like a &lt;a href="http://catb.org/jargon/html/W/write-only-language.html"&gt;write-only language&lt;/a&gt;, an impression &lt;a href="http://en.wikipedia.org/wiki/Write-only_language"&gt;which is not uniquely mine&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Some Perl programmers share a common predilection for something which users of another language often called read-only, &lt;span class="caps"&gt;APL&lt;/span&gt;, prided theselves on writing, one-liners. And this has inspired &lt;a href="http://www.fepus.net/ruby1line.txt"&gt;catalogs of Ruby one-liners&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve found that a lot of the literature of Perl isn&amp;#8217;t very understandable.  I&amp;#8217;ve found that even Perl code which I&amp;#8217;ve written myself is impenetrable when I come back to it weeks, or even days after writing it.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m sure that there are Perl programmers who don&amp;#8217;t find this to be true, just like my French friends seem to be able to converse without problems, but I continue to only muddle along in both languages.&lt;/p&gt;


	&lt;p&gt;The key indicator of Perl programs written in Ruby is the use of all those global variables with funny names like $*, $&amp;#38;, $0, etc.  Perl programmers love them since they are in Ruby for compatibility with Perl.  When I see them, my eyes glaze over, and my mind says &amp;#8221;$&amp;#38;^+_&amp;#8221;&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not trying to antagonize the Perl programmers among the Ruby community, anymore than I try to antagonize my francophone friends, in fact I&amp;#8217;ve got great love for some particular francophones and perlographs.&lt;/p&gt;


	&lt;p&gt;But I&amp;#8217;ll probably never understand them as well as I&amp;#8217;d like to.&lt;/p&gt;


&lt;h2&gt;P.S. Not (Directly) Borrowed From Perl&lt;/h2&gt;
One feature of Perl is the use of &lt;a href="http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29"&gt;sigils&lt;/a&gt; as markers on variable names.

	&lt;p&gt;Ruby uses sigils to mark some variables as being globals (there&amp;#8217;s that $ again, but the names don&amp;#8217;t have to be funny), instance variables, or class variables.&lt;/p&gt;


	&lt;p&gt;The difference is that Perl uses sigils to distinguish the types of variables, something which is unnecessary in Ruby since everything is an object.  Ruby instead uses them to find the variable binding in the case of a reference, or where to put it in the case of an initial definition.  A Ruby variable comes into existance the first time it is mentioned in the execution of a Ruby program, and it goes into the global variable &amp;#8220;pool&amp;#8221;, the current instance, or the current instances class depending on the sigil.  No declaration is necessary as compared to Smalltalk, for instance, where instance and class variables are &amp;#8216;declared&amp;#8217; by telling the class about them, and globals are defined by putting them in the system dictionary. While Perl variables aren&amp;#8217;t explicitly declared either, the real motivation for sigils in Perl is to associate a type with a variable.&lt;/p&gt;


	&lt;p&gt;Perl also makes use of the fact that all variables start with a sigil to automatically interpolate variables into strings. Since ruby variables don&amp;#8217;t all start with a sigil, Ruby uses #{} as a marker to interpolate an expression int to a string.  Note that if that expression is just a global, class or instance variable (all of which start with a sigil) a simple # will do the job.&lt;/p&gt;


	&lt;p&gt;So Perl uses sigils more as a way to express type, a static concept, in a dynamically executed language, and Ruby uses them to avoid static declarations, and make variable definition and use dynamic.&lt;/p&gt;</description>
      <pubDate>Wed, 16 Aug 2006 11:03:18 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:5abc0671-cdcc-47ee-b5fa-060f2172c170</guid>
      <author>Rick DeNatale</author>
      <link>http://talklikeaduck.denhaven2.com/articles/2006/08/16/a-perl-of-great-price</link>
      <category>ruby</category>
      <category>perl</category>
      <category>style</category>
      <category>peeves</category>
      <category>literateprogramming</category>
      <trackback:ping>http://talklikeaduck.denhaven2.com/articles/trackback/19</trackback:ping>
    </item>
  </channel>
</rss>
