On Fri, Apr 25, 2008 at 8:46 PM, Doran, Michael D <[EMAIL PROTECTED]> wrote:
> Back-story:
>
> I have a Perl CGI program. The CGI program needs to utilize variables in
> one of several separate configuration files (packages). The different
> packages all contain the same variables, but with different values for those
> variables. Each package represents a different language for a multilingual
> interface for the CGI program. e.g. English.pm, French.pm, Spanish.pm.
>
> The CGI program can't determine which language package is needed until it
> parses the form input and does a test based on the value for a query string
> name/value pair. Based on the test, I assign a value to a package load
> command (i.e. 'use English' or 'require English'). Because of that, I can't
> load the package with "use Package" since "use" runs at compile time, before
> I can assign a value to it.
>
You can use UNIVERSAL::require to do this:
use UNIVERSAL::require;
use CGI;
my $cgi = new CGI();
my $package = 'Language::' . $cgi->param('lang'); # say, 'English'
$package->use;
my $thing = $package->new();
Hope that helps. FWIW, we use U::r pretty heavily inside Evergreen.
--
Mike Rylander
| VP, Research and Design
| Equinox Software, Inc. / The Evergreen Experts
| phone: 1-877-OPEN-ILS (673-6457)
| email: [EMAIL PROTECTED]
| web: http://www.esilibrary.com