Date: 2008-11-20 17:47:00
Tags: perl
stupid perl

I just spent at least an hour debugging a problem that I can blame squarely on Perl. Consider the following declaration:

  %lookup = {
    A => 1,
    B => 2
  };

This looks like a perfectly reasonable hash initialisation, right? However, trying to actually reference anything that should be in this hash results in undef. What's the problem?

The answer is I used the wrong kind of brackets! Even though curly brackets are used for all other hash type things, you can't use them here because they mean something completely different and unexpected. The correct declaration is:

  %lookup = (
    A => 1,
    B => 2
  );

It turns out that on the platform where I'm doing this, I have to use a really really old version of Perl (5.002). The -w switch apparently doesn't detect this problem in 5.002. In later versions, you will at least get this sort of warning:

  $ perl -w -e '%a = {}'
  Reference found where even-sized list expected at -e line 1.

Bloody hell. I hate Perl. Years ago when I was writing Perl stuff regularly I would have remembered this, but it's just not the sort of thing you recall after using sensible languages in the meantime.

[info]goulo
2008-11-20T11:03:00Z
This story of perl's happy acceptance of so many unintentional syntax pseudo-errors and typos sparked an amusing idea:

perl could be even more perl-ish if it simply interpreted any statement with syntax errors as a comment. :)
[info]paradox0220
2008-11-20T15:29:00Z
I warms my heart to see some good Perl bashing!

Sadists created that language.
Greg Hewgill <greg@hewgill.com>