2012-06-25

TOC Perl Reimplementation

This morning I reimplemented the code that generates the archive listing in Perl.

So the following bash script:

#!/bin/bash
cd entries
grep '###' * | tac | sed -e 's/### //' | awk -F: '
{print "<a href="index.html#">" $2 "</a><br>"; }
' &gt; ../toc.middle

became the following using Perl instead of the specific bash commands:

#!/bin/bash
cd entries

perl -lne '
/###/ &amp;&amp; print "$ARGV:$_";
' * | perl -e '
@ls = ; print foreach (reverse @ls);
' | perl -lpe '
s/### //
' | perl -lna -F: -e '
print qq(<a href="index.html#$F[0]">$F[1]</a><br>)
' &gt; ../toc.middle

So, the Perl, is longer, and not necessarily any faster, because I’m actually executing a seperate instance of Perl for each of the bash commands I’m replacing. So, it could conceivably be even slower than the original bash script.

But it was interesting to do.

BUGS

The previous post revealed a bit of a bug with the archive listing generation. The fact that the scripts in the post had the symbols that were being searched for, meant some false entry listings were generated using those lines from the post, instead of just the post titles.

Also, I noticed that the version of Markdown that I’m using with Perl (the original John Gruber version) does not support a syntax that I was using in the Node.js version to indicate code blocks.

So, I need to look back through previous posts for any that used that syntax and change them, otherwise they won’t display correctly with the new site generation.

Update: Archive BUG fixed

I fixed the bug in the archive listing.

I still need to look through all entries for the previous version of code block syntax.

Update 2: Code Blocks fixed

Went through and changed all previous entries with code blocks to use the original markdown code block syntax.

Good and Evil in Perl

I had a thought today about Ruby, PHP and Perl while reading a post on programming languages. It reminded me of the movie Twins…

  • It seems like Ruby took as much of the good stuff from Perl as it could.
  • It seems like PHP may have ended up with the bad stuff.

But Perl gives you both good and evil in one complete language 🙂

Perl vs Ruby = Functional vs Object-Oriented

Having just recoded this blog in Perl, I’ve been wondering also how the code would look in Ruby.

One thing I’ve been thinking about today regarding Perl and Ruby, is that once you go beyond a simple procedural paradigm, they differ significantly in what emphasis they make easy.

So, for example, I know you can do object-orientation in Perl, but I personally haven’t wanted to deal with it for my programs, whereas in Ruby, object-orientation is a reasonable default.

However, Ruby is <em>so</em> object oriented that while it provides some constructs that can mimic functional programming, you are really still dealing with an Object paradigm, and I personally don’t know how to do really functional type things, whereas Perl really makes it quite easy to program in a functional style, with good support from the language.

So basically Ruby tends toward being an Object-Oriented scripting language, and Perl tends toward being a Functional scripting language, once you move beyond simple procedural scripting.

I like some of the look of Ruby better than Perl, but I’ve tended to think in a more Functional than Object-Oriented mindset for the last several years, so I actually may prefer Perl for what it can do in a functional style.

Interesting Perl Discussion

Some interesting discussions:

Is Perl still a useful viable language?

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s