Hi Mike,

> You can use UNIVERSAL::require to do this:

Hmmm.  This is interesting.  I wasn't familiar with this module, so will be 
giving it a look.

Thanks!

-- Michael

# Michael Doran, Systems Librarian
# University of Texas at Arlington
# 817-272-5326 office
# 817-688-1926 cell
# [EMAIL PROTECTED]
# http://rocky.uta.edu/doran/



-----Original Message-----
From: Mike Rylander [mailto:[EMAIL PROTECTED]
Sent: Mon 5/5/2008 8:57 PM
To: Doran, Michael D
Cc: Perl4lib
Subject: Re: Importing Perl package variables into a Perl script with "require"
 
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


Reply via email to