Despite the fact the author of the blog post had pulled the Python code from answers to Project Euler the pythonista’s quite correctly cried foul because it wasn’t well written idiomatic python example and so was an unfair comparison.

There’s a lot of code out there posted on those intertubes over the years. However languages and practises evolve but unfortunately intertube posts can remain set in stone! Perl is often weighed down by its past history on the intertubes. One good way forward is just to produce more Modern Perl posts.

Anyway i digress, so moving on lets take a look at the Euler 4 – Finding Palindroms. This was the Clojure example that was put forward in the blog post:

Despite being formatted for twitter (ie. one line) i found it easy to follow through the logic.

Ruby & Python are not the only languages that can produce an elegant solution! So not to be out done here is a Perl example. In fact its the exact same code repeated three times but formatted differently:

Like this:

Related

Just to confirm your findings, the python example took about 2.5 seconds to run on my machine (python 2.6) and then Perl example took less than .5 seconds (perl 5.8.9). And I couldn’t get the ruby example to run (I’m guessing it didn’t work on 1.8.6).

I didn’t bother testing it with Python from here because the Python that ships with Mac OSX Tiger is notoriously slow for some reason and it wouldn’t have been fair to compare it to the Perl times (which comes in on average at 0.85 secs using my own compiled 5.10.1 here).

The Ruby example requires 1.9.1. Don’t have that or Clojure loaded here but based on times given in the blog posts it doesn’t look likely that they will beat the Perl times.

About…..

My name is Barry Walsh. I'm a freelance IT consultant from London, UK. [more]

This blog is mostly about Perl programming because this is what I use and love (and occasionally hate!) for the majority of my working (and sometimes non-working) day.

Occasionally I will touch on other subjects like PostgreSQL, Mac OSX, UNIX, Linux, Ruby, jQuery, Javascript, XML and many more techie things that I also play with regularly. Other non techie aspects of my life may slip in now and again but I'll try and keep that to a minimum because its normally boring anyway :)