Monday, May 18, 2009

Perl, Template Toolkit, and GraphViz

Our largest Catalyst application ( is composed of 184 templates. I get lost sometimes while template diving, and forget the parent node(s) of my current node.

Inspired by The Perl Review Issue 4.1, I decided to give GraphViz a stab. To my surprise, I got it working very quickly. I wrote a quick CGI hack that lets me click on any of my templates from a list on the left, and it draws an INCLUDE diagram of all downstream templates for me. Here's a screen shot of the CGI in action:

Pretty slick, huh? Here's what it drew for our, which is the parent of many of our templates:

You could throw the same crude implementation at any tree, really. I think I'll try all the use statements in our in-house perl code base next. :)

The source code is here: Enjoy!

Tuesday, May 5, 2009


Oh, that's cute. The DNS domain is set up to a redirect to the text version of the program I hadn't seen that trick before. :) is a pretty slick little program with color ASCII output to give you a quick rundown of the status of, and suggestions of how to improve, the health of your MySQL databases. I like it. :)

Sunday, May 3, 2009

Tweak the Perl regex engine: assign to pos()

OK, Perl is way too cool.

I was minding my own business, searching for every occurrence of 'CCAGC' in E-coli, when I hit a snag. Several hundred of my known locations weren't showing up.

Why? Because the Perl regular expression engine, by default, starts searching for the next occurrence of something after the end of the occurrence it just found. This is what most humans want. But you may notice that in the string 'CCAGCCAGC' the thing I'm searching for ('CCAGC') overlaps itself, so the regex engine doesn't see the second one.

"Crap," I thought.

But this is Perl -- maybe there's a way? 30 seconds in the documentation (perldoc -f pos) and it said I could assign to pos(). Really? Sweet! Problem solved!


use strict;

open (IN, "E_coli.seq");
my $seq = <IN>;
chomp $seq;
close IN;

my $find_this = 'CCAGC';
while ($seq =~ /$find_this/g) {
my $start = pos($seq) - length( $find_this ) + 1;
my $stop = pos($seq);
pos($seq) = $start;
print " Found $find_this at [$start..$stop]\n";

Friday, May 1, 2009

Two of Life's Greatest Joys

I think in their heart of hearts each parent hopes that their children will be like them. After all, they usually invest a great deal of energy throughout the child-rearing to "raise them up right" (that is, "right" as the parents interpret it). That only makes sense: if you're an idealist, say, you naturally hope your kids will have high ideals.

But what the parenting manuals fail to mention is that the greatest blessing kids bring may not be the ways in which they resemble or emulate you, but in the ways they differ from (and may even challenge) you. Their interests, their life views, their choices, their knowledge--all these, and more, are often "beyond" you, that is, they are often beyond your understanding AND beyond your life experience. As they mature, this becomes increasingly evident. It seems ever more true, as Gibran writes of children:

You may give them your love but not your thoughts,
For they have their own thoughts.
You may house their bodies but not their souls,
For their souls dwell in the house of tomorrow,
which you cannot visit, even in your dreams.
You may strive to be like them, but seek not to make them like you.
For life goes not backward nor tarries with yesterday.

The poet likens this life process to archery, the parents being the bow and the children the arrows. It's an image that gives me great joy as I see my sons see and do things beyond my ken, but not beyond my love for them.