Gossamer Forum
Home : General : Perl Programming :

use lib $path ?

Quote Reply
use lib $path ?
I am trying to do something like
Code:
my $path = '/path/to/lib';
use lib $path;
but that doesn't work (Empty compile time value given to use lib ...).

Any solutions to this?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Post deleted by Wil In reply to
Quote Reply
Re: [yogi] use lib $path ? In reply to
That's because the "use" line is evaluated before my $path = "/path/to/lib";

You can do it like:

BEGIN { $path = "/path/to/lib" }

use vars qw/$path/;
use lib $path;

Last edited by:

Paul: Apr 12, 2002, 5:15 AM
Quote Reply
Re: [Paul] use lib $path ? In reply to
Oops sorry make sure you put use vars qw/$path/; _above_ BEGIN {}
Quote Reply
Re: [yogi] use lib $path ? In reply to
Just incase I totally confused you :)

Code:
#!/usr/bin/perl

use strict;
use vars qw/$path/;

BEGIN { $path = "/foo/bar" };

use lib $path;

print "Content-type: text/plain\n\n";
print join "\n", @INC;

Last edited by:

Paul: Apr 12, 2002, 5:42 AM
Quote Reply
Re: [Paul] use lib $path ? In reply to
Thanks a lot for your answers. The case I told you about works now, but what about the following:
Code:
#!/usr/bin/perl
use strict;
use lib '/home/yoga/cgi-bin/links/admin';
use GT::Base;
use GT::Plugins;
use Links;
use Links::Plugins;
use vars qw/$path/;

BEGIN {
$path = Links::Plugins->get_plugin_user_cfg('MyPlugin')->{my_path};
};

use lib $path;

The plugin is installed. And the user config is there...

Any ideas

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] use lib $path ? In reply to
What is happening?
Quote Reply
Re: [Paul] use lib $path ? In reply to
Same as above: Empty compile time value given to use lib at test.pl line 14

It doesn't get the plugin config, it says $path = undef ....

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Apr 12, 2002, 5:40 AM
Quote Reply
Re: [yogi] use lib $path ? In reply to
Instead of a second use lib line should should probably use:

unshift @INC, $path;

You don't need the begin block then either.
Quote Reply
Re: [Paul] use lib $path ? In reply to
No, that doesn't work.

The thing is I want to use GForum modules (and database defs) in a Links SQL plugin. For that I need the GForum admin path, which is stored in the plugin user cfg...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] use lib $path ? In reply to
OK, the following works (for future reference):
Code:
#!/usr/bin/perl
use strict;
use lib '/home/yoga/cgi-bin/links/admin';
use GT::Base;
use GT::Plugins;
use Links;
use Links::Plugins;
use vars qw/$path/;

BEGIN {
Links::init('/home/yoga/cgi-bin/links/admin');
$path = Links::Plugins->get_plugin_user_cfg('MyPlugin')->{my_path};
}

use lib $path;

# Rest of code
Basically, I forgot to call Links::init(); Thanks for the BEGIN thing anyway....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] use lib $path ? In reply to
Or you can do away with the BEGIN block and it can be just:
Code:
use lib;
$path = '...';
lib->import($path);

Adrian
Quote Reply
Re: [brewt] use lib $path ? In reply to
Oh cool. I didn't know about that, it doesn't seem to be mentioned on the lib perldoc page.
Quote Reply
Re: [brewt] use lib $path ? In reply to
The code you gave doesn't really work for me.

$path is correctly imported into @INC, but then if I do "use MODULE;" (where MODULE resides in the newly imported directory), perl can't find it and in the error message it says that @INC does not contain $path...

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Apr 17, 2002, 10:09 PM
Quote Reply
Re: [brewt] use lib $path ? In reply to
Hi Adrian. I just tried your suggestion for something I am doing, and it didn't seem to work :/

Quote:
The remote procedure call failed.

...the code is;

Code:
my $installation = $IN->param('installation');
use lib;
lib->import($installation);
use GT::SQL;
my $db = new GT::SQL $installation;

Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates