If you are using at least Perl 5.10, the Module::Load module should be in core. It would allow an implementation something like this:
# Arguments are city code ('lon' or 'par') and an environment ('prod' +or # 'test') use Module::Load qw{ load }; sub load_database_module { my ( $city, $envir ) = @_; state $city_map = { lon => 'London', par => 'Paris', }; state $envir_map = { prod => 'Production', test => 'Test', }; state $type_map = [ qw{ Prod` Test } ]; $city_map->{$city} or die "Invalid city '$city'"; $envir_map->{$envir} or die "Invalid envir '$envir'"; my $class = sprintf 'App::%s::%s::LogTable', $city_map->{$city}, $envir_map->{$envir}; load( $class ); return $class; }
In reply to Re: How to dynamically invoke one of several similarly named modules
by Anonymous Monk
in thread How to dynamically invoke one of several similarly named modules
by onemojofilter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |