I'm a big one for understanding and making elegant use of layers of software, from the BIOS to the OS to the layers of applications, but I bit myself with a very simple gotcha that I'd like to share.

In my web work, I use Apache, mod_perl, and HTML::Embperl extensively. I'm a very code-oriented wonk, so Embperl suits my development style a lot more than some of the other templating systems available for Perl. One of the neat features of Embperl is it's ability to dynamically create a table for you from an array such as the result of an SQL query. Neat stuff that blows PHP completely out of my toolbox!

Unfortunately, the key element of this capability is an Embperl variable called $row. I also use Spreadsheet::WriteExcel to create spreadsheet files from the SQL data, and it's served me well. My code to date has always spawned a regular Perl program to do the file-writing, and it works. Over the last few days, I've been working on cleaning up my routines to make them more general and simpler, and I went 'round and 'round trying to figure out why my web daemon would hold my CPU hostage whenever I tried to write to the file. I mean, I could create the file, create a worksheet, and even set the name of it, but as soon as I tried to write anything, even a blank space, it would go for a Sunday drive and not come back!

I'm sure you all know the punch line: I'd used $row and $col as my spreadsheet-position variables and they clobbered Embperl.

Moral of the story: Always spend some cycles thinking about the layers of software that support your program when a bug seems intractable! :D

Replies are listed 'Best First'.
Re: Layers of Software
by tirwhan (Abbot) on Oct 19, 2005 at 15:54 UTC

    Quick question: was the $row variable lexically scoped, i.e. declared with my in your code? If so, I'm curious how Embperl picked it up, I thought this sort of thing is exactly what lexical scoping is supposed to prevent.

      Wasn't originally, is now. As well as being renamed for clarity. :D
        Ah right, thanks. In which case, wouldn't the other moral of the story be: Always use strict? ;-)