in reply to Dynamicaly loading modules
So instead I would use require as follows:
Note that it is important to have a check on allowed packages for security reasons. (Never trust the user!) But for a CGI application if your naming scheme is fixed it may make sense to just use a grep to see that the package is implemented, and then produce $pack by a direct manipulation. That is slightly less code, but is less flexible.my %package = qw( W pack_W X pack_X Y pack_Y Z pack_Z ); unless (exists $package{$state}) { # Handle this error somehow... die "State '$state' is not implemented"; } my $package_file = "$package{$state}.pm"; $package_file =~ s~::~/~g; require($package_file); my $app = $package{$state}->new(%stuff); $app->run;
|
|---|