Tuesday, July 27, 2004

Polymorphic Subroutines

A nice Perl hack that allows you to do (even more) complex polymorphism inside the eSTAR agent code base than I was already doing, I'm sure that this will scare my postgrad Eric quite badly.

my $stub = q(
my $stmt = $dbg->prepare("SQL");

while ( my ($name, $sql) = each %queries ) {
my $body = $stub;
$body =~ s/SQL/$sql/;
eval "sub $name { $body }";

There seems to be some people objecting to the above in the session on maitainability grounds, but I rather like it.