SPUG: conditional module loading
John W. Krahn
krahnj at telus.net
Fri Jul 13 22:49:13 PDT 2007
Charles Connolly wrote:
> Hi,
Hello,
> I would like to load one of two modules depending on the value of an
> environment variable. It looks like both modules are loaded in spite of the
> 'use' statements being in an if/else block, and the 'elsif' part not being
> entered. Any ideas what's going on? I'm stumped. Thanks for your thoughts.
>
> Chuck Connolly
>
> Here's the test script test.plx:
> #! /usr/bin/perl -w
> use strict;
>
> BEGIN {
> if ( $ENV{ test_status } == 1 ) {
> use TestMod;
> warn "using TestMod\n";
> } elsif ( $ENV{ test_status } == 2 ) {
> use Test2Mod;
> warn "using Test2Mod\n";
> } else {
> die "unknown value of test_status: $ENV{ test_status }\n";
> }
> }
use if $ENV{ test_status } == 1, TestMod;
use if $ENV{ test_status } == 2, Test2Mod;
perldoc if
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
More information about the spug-list
mailing list