Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Is there a way to define Links.pm on the fly

Quote Reply
Is there a way to define Links.pm on the fly
Hi,

In all the scripts one of the first line is use Links; telling the script to use Links.pm.

is there anyway to define a different .pm configuration file on the file?

I tried this already:
$table = $in->param('db') | | "Links";
use $table;

That just gives me a compilation error.

what I'm trying to do is redefine directories based on the database I'm using. I am able to do this:
if ($table eq "Links") {
use Links_custom;
}
The program will then go into Links_custom.pm and build based on those directories.

But that would entail using an if statement for each possible $in->param('db') which would be extremely cumbersome. Any ideas on how to make something like:

use $table;

evaluate properly?

Thanks,

Kyle
Quote Reply
Re: Is there a way to define Links.pm on the fly In reply to
The use function is called before any other code, during perl's compile phase.

So if you do:

if (somecondition) {
use Links;
}

Links will already be used before the if is evaluated.

What you want to do is either use require or throw it in a BEGIN block.

What I would do is:

BEGIN {
use CGI;
if (CGI->param('something')) {
require Links;
}
else {
require SomeotherLinks;
}
};

and that will be donebefore anything else.

Hope that helps,

Alex