in reply to Searching file extensions

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

Replies are listed 'Best First'.
Re^2: Searching file extensions
by Anonymous Monk on Jun 27, 2013 at 14:24 UTC
    Why am I recieving the error message: Can't locate File/Find/Rule.pm in @INC It didn't seem to have any problem with File:Find