I had a similar problem a while back, which I solved with a dispatch table. Basically, this is a hash where the values are referances to subroutines. Example:
my %DISPATCH = (
html => \&html,
htm => \&html,
pl => \&pl,
cfm => \&cfm,
);
$_ = '/path/to/file.ext';
$_ =~ /\.(\w+)\z/;
$DISPATCH{$1}->($_, @other_args) if exists $DISPATCH{$1};
sub html { . . . }
sub pl { . . . }
sub cfm { . . . }
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
|