First of all all of the modules got loaded at compile time,
see
use for why.
So instead I would use require as follows:
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;
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.