use lib "mylibrary" question and general config file...

A

alexandre.melard

Hi there,

Promise, today, I will be very polite ;-)

I know I will surprise some of you by my question, but nevertheless I
have to ask...

I use a set of personal classes in a program which I locate using:

use lib "path/to/my/classes"

Everything is going well until I decide to share my program with other
people.
I decide to set up a configuration file in order to give the users a
chance to let the program find the necessary directories on their
systems (Linux gentoo for me).

I therefore put my main variables in a file "myconfig.rc" Then I load
the variables in my perl script using a loadConf sub.

The problem appear here! --> . <--

How is it possible to load the path/to/my/classes from a config file?
I tried to load my "config.rc" before loading the "use" statements, but
it is not working (Perl seems to load the "use" before anything else).

so it is not possible to do:

$pathToLib = undef;
unless( loadConf() ) { print "Error, vould not load conf" }

use lib "$pathToLib";

How could I do that?

Another big big question is: where can I store my config file on the
file system in order to be able to find it? I know I should put my
classes somewhere in the @INC or in my $ENV{PATH} but cannot figure out
where... I cannot put it in the home directory as the program is likely
to be used by different people with different home directory but the
conf need ot be the same for everybody.

I know you are very good to advise me on some reading, please let me
know were to dig and I will dig gldely :)

As usual, I greatly apreciate your help, believe it or not, I followed
perl course at uni and they **forgot** to let us know about all these
rather important things.

Alexandre.
 
G

Gunnar Hjalmarsson

How is it possible to load the path/to/my/classes from a config file?
I tried to load my "config.rc" before loading the "use" statements, but
it is not working (Perl seems to load the "use" before anything else).

I think you can call loadConf() from within a BEGIN block before the
use() statement.

BEGIN { loadConf() }
use lib '/path/to/my/classes/';

(untested)
Another big big question is: where can I store my config file on the
file system in order to be able to find it?

How about the same directory as the calling script? See "perldoc
FindBin" for one way to determine that directory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top