Programming Perl Instead of Ruby

I’ve got a new job and it’s working almost completely in Perl. Who’d have thought? Fortunately, it really is true that if you know one programming language fairly well, you’ll understand others fairly easily. Modifying code in Perl is easy as long as I have other code to refer to, and I often forget it’s a new language. Learning all the names, faces and practices in my new job is much harder than learning a bit of new syntax. However, if I had to sit down and write something in Perl from scratch it would not go well.

There’s definitely a few things I’ve noticed about Perl that I don’t like compared to Ruby:

  • Sigils. I keep forgetting to prepend my variables with those $@% sigils. That’s not me cursing there, those are the sigils for scalars, arrays and hashes. The worst is when you’re references the whole array (@foo) you use a different sigil than when you’re referencing a scalar element in the array ($foo[0]).
  • Objects feel like a hacked up addon to the language. You have to “bless” things to make them objects and you’re always passing around references to $self to object methods. You can’t make methods private. Weird stuff.
  • No interactive shell built in. I loved having irb to try things out when I was learning Ruby – heck, I still do. Fortunately, after a bit of searching and bad advice on just using the Perl debugger I found Perl Console.
  • Always needing to say “my variablename” instead of just “variablename” if I want local variables. It seems like variables should be local by default and you say something if you want to make them local.

There’s some things about Perl I’m not sure if I like or dislike yet:

  • Default variables. Strangely named variables like $ and @ pop up everywhere. The idea is if you don’t want to come up with a name for variables while you’re iterating or passing parameters, you don’t have to thus saving all that typing and thinking. However it certainly makes the code harder to read for those who don’t know Perl and I suspect it might make things always harder to read even once I get used to it.
  • Regular expressions everywhere. This will be good for me to get better with this powerful feature, but damned if regular expressions aren’t ugly.
  • There’s always more than one way to do something. This is true in most every language, but Perl seems to take a lot of pride in it, and often the idiomatic Perl way of doing something is quite a bit harder to read than the non idiomatic way.

The main thing I like about Perl so far is that the Perl community seems to have a sense of humor. Perl books are always making jokes and variables in Perl code are given entertaining names.

Aside from the new language difference, the new job is great for me to get used to coding in a large codebase and with teams. We use quite a few Extreme Programming practices like test driven development, and even more impressive, pair coding. These practices more than make up for anything I don’t like about Perl.