<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Simple Recursion in Perl</title>
	<atom:link href="http://pthree.org/2007/01/18/simple-recursion-in-perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/</link>
	<description>Linux.  GNU.  Freedom.</description>
	<pubDate>Tue, 02 Dec 2008 16:03:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7-RC1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris Blanc</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-83357</link>
		<dc:creator>Chris Blanc</dc:creator>
		<pubDate>Mon, 10 Dec 2007 19:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-83357</guid>
		<description>I've unleashed a script inspired by your approach to recursivity here:

http://www.chrisblanc.org/blog/?p=77

It's a simple linefeed filter. By the way, don't OGGs sound better than other file formats at the same bitrate? Amazing compression.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve unleashed a script inspired by your approach to recursivity here:</p>
<p><a href="http://www.chrisblanc.org/blog/?p=77" rel="nofollow">http://www.chrisblanc.org/blog/?p=77</a></p>
<p>It&#8217;s a simple linefeed filter. By the way, don&#8217;t OGGs sound better than other file formats at the same bitrate? Amazing compression.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Toponce: Recursion In Python // The Linux Index</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-64581</link>
		<dc:creator>Aaron Toponce: Recursion In Python // The Linux Index</dc:creator>
		<pubDate>Thu, 09 Aug 2007 18:24:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-64581</guid>
		<description>[...] took my Perl script that I wrote some time ago, and rewrote it in Python. The exercise of the initial Perl script, was to get a better handle on [...]</description>
		<content:encoded><![CDATA[<p>[...] took my Perl script that I wrote some time ago, and rewrote it in Python. The exercise of the initial Perl script, was to get a better handle on [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Toponce &#187; Blog Archive &#187; Recursion In Python</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-64554</link>
		<dc:creator>Aaron Toponce &#187; Blog Archive &#187; Recursion In Python</dc:creator>
		<pubDate>Thu, 09 Aug 2007 12:59:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-64554</guid>
		<description>[...] took my Perl script that I wrote some time ago, and rewrote it in Python. The exercise of the initial Perl script, was to get a better handle on [...]</description>
		<content:encoded><![CDATA[<p>[...] took my Perl script that I wrote some time ago, and rewrote it in Python. The exercise of the initial Perl script, was to get a better handle on [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-27074</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Wed, 24 Jan 2007 02:00:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-27074</guid>
		<description>oh, you know you want to just use:
&lt;code&gt;
find . -name "*.ogg"
&lt;/code&gt;
:)</description>
		<content:encoded><![CDATA[<p>oh, you know you want to just use:<br />
<pre class="php">find . -name <span style="color: #ff0000;">&quot;*.ogg&quot;</span></pre><br />
 <img src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-26815</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Sun, 21 Jan 2007 15:33:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-26815</guid>
		<description>I'll have to give that bit of code a look over when I get to work.  File::Find looks like it will do exactly what I need.

I don't know why you were getting files that were everything &lt;b&gt;but&lt;/b&gt; *.ogg files.  Looking over the code, everything is perfect.  Maybe I'm missing something from the copy/paste.</description>
		<content:encoded><![CDATA[<p>I&#8217;ll have to give that bit of code a look over when I get to work.  File::Find looks like it will do exactly what I need.</p>
<p>I don&#8217;t know why you were getting files that were everything <b>but</b> *.ogg files.  Looking over the code, everything is perfect.  Maybe I&#8217;m missing something from the copy/paste.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harley Pig</title>
		<link>http://pthree.org/2007/01/18/simple-recursion-in-perl/#comment-26812</link>
		<dc:creator>Harley Pig</dc:creator>
		<pubDate>Sun, 21 Jan 2007 14:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2007/01/18/simple-recursion-in-perl/#comment-26812</guid>
		<description>When I ran this I got a file full of data that did *not* include ogg files.

I spent more time than I should have trying to figure out why this was.  I never did figure it out. I'm assuming you were able to make the code work the way you wanted it to.  From what I can tell though, it looks ok.  A global counter variable in this circumstance isn't really a bad thing.

I know you're doing this to learn recursion, at least a better understand of it in perl, but I can't just let this pass without pointing out File::Find.

File::Find will take care of most of the heavy lifting for you.

Some notes:

  Let the shell do the hard work.  Why take the trouble to open a file when
  you can redirect it?  Call it like &lt;code&gt;inventory.pl &gt; oggfiles.txt&lt;/code&gt;

  This bit of code prints out every single directory name, regardless of
  whether or not there is an ogg file in it or its children.  You'd need to
  store the data and then filter it once all the data was gathered.

  The 'preprocess' portion of the code is called after each readdir with the
  file list passed in.  This allows us to set up the indent variable and
  filter out the 'hidden' directories.

  The 'postprocess' portion of the code is called after each directory has
  been processed (i.e., the list returned by preprocess has been iterated
  through).  This allows us to trim the indent variable.

  The 'wanted' portion of the code is called for every single file found in
  the tree.

&lt;code&gt;
#!/usr/bin/perl -w

use strict;

use File::Find;

my $indent = '';

find({
  'wanted' =&gt; sub { print "$indent$_\n" if /\.ogg$/i; },

  'preprocess' =&gt; sub {
    print "$indent$_\n";
    $indent = "$indent  ";
    sort grep { ! /^\./ } @_;
  },

  'postprocess' =&gt; sub { $indent = substr( $indent, 0, -2 ); },

}, '.');
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>When I ran this I got a file full of data that did *not* include ogg files.</p>
<p>I spent more time than I should have trying to figure out why this was.  I never did figure it out. I&#8217;m assuming you were able to make the code work the way you wanted it to.  From what I can tell though, it looks ok.  A global counter variable in this circumstance isn&#8217;t really a bad thing.</p>
<p>I know you&#8217;re doing this to learn recursion, at least a better understand of it in perl, but I can&#8217;t just let this pass without pointing out File::Find.</p>
<p>File::Find will take care of most of the heavy lifting for you.</p>
<p>Some notes:</p>
<p>  Let the shell do the hard work.  Why take the trouble to open a file when<br />
  you can redirect it?  Call it like <pre class="php">inventory.pl &gt; oggfiles.txt</pre></p>
<p>  This bit of code prints out every single directory name, regardless of<br />
  whether or not there is an ogg file in it or its children.  You&#8217;d need to<br />
  store the data and then filter it once all the data was gathered.</p>
<p>  The &#8216;preprocess&#8217; portion of the code is called after each readdir with the<br />
  file list passed in.  This allows us to set up the indent variable and<br />
  filter out the &#8216;hidden&#8217; directories.</p>
<p>  The &#8216;postprocess&#8217; portion of the code is called after each directory has<br />
  been processed (i.e., the list returned by preprocess has been iterated<br />
  through).  This allows us to trim the indent variable.</p>
<p>  The &#8216;wanted&#8217; portion of the code is called for every single file found in<br />
  the tree.</p>
<p><pre class="php"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl -w</span>
&nbsp;
use strict;
&nbsp;
use <a href="http://www.php.net/file"><span style="color: #000066;">File</span></a>::<span style="color: #006600;">Find</span>;
&nbsp;
my <span style="color: #0000ff;">$indent</span> = <span style="color: #ff0000;">''</span>;
&nbsp;
find<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #ff0000;">'wanted'</span> =&gt; sub <span style="color: #66cc66;">&#123;</span> <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$indent$_<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> /\.ogg$/i; <span style="color: #66cc66;">&#125;</span>,
&nbsp;
  <span style="color: #ff0000;">'preprocess'</span> =&gt; sub <span style="color: #66cc66;">&#123;</span>
    <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;$indent$_<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #0000ff;">$indent</span> = <span style="color: #ff0000;">&quot;$indent  &quot;</span>;
    <a href="http://www.php.net/sort"><span style="color: #000066;">sort</span></a> grep <span style="color: #66cc66;">&#123;</span> ! /^\./ <span style="color: #66cc66;">&#125;</span> @<a href="http://www.php.net/_"><span style="color: #000066;">_</span></a>;
  <span style="color: #66cc66;">&#125;</span>,
&nbsp;
  <span style="color: #ff0000;">'postprocess'</span> =&gt; sub <span style="color: #66cc66;">&#123;</span> <span style="color: #0000ff;">$indent</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$indent</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">-2</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>,
&nbsp;
<span style="color: #66cc66;">&#125;</span>, <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span>;</pre></p>
]]></content:encoded>
	</item>
</channel>
</rss>
