Gossamer Forum
Home : General : Perl Programming :

Possible with modules?

Quote Reply
Possible with modules?
I've just been playing with something. Basically, what I want to do is something like;

Code:
#!/usr/bin/perl

$type = "1"; # use 1 or 0

if ($type) {
use One::Module;
} else {
use Another::Module;
}

The problem is, that I still get error messages for one of the modules. The whole idea behind this is to let a user decide what module they want to use. If they have one module installed, then they should be able to choose that one. If not, then they can use the old one.

Any suggestions? Is it even possible? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Possible with modules? In reply to
Code:
sub _require
#----------------------------------------------------------------
# Usage: _require($type);

my $type = shift;
my $package = $type ? 'This::Module' : 'That::Module';

{
local $SIG{__DIE__};
eval {
require $package;
};
$@ and die "Oops: $@";
}

return 1;
}

...or you could just pass in the package name and do:

my $package = shift;
Quote Reply
Re: [Paul] Possible with modules? In reply to
Ah....just figured it out. I needed 'require' instead of 'use'. Thanks for the code though Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Possible with modules? In reply to
Yup, because "use" is evaluated at compile time, but "require" is evaluated at run time.