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

Discussion in 'Perl Misc' started by alexandre.melard@gmail.com, Jul 31, 2005.

  1. Guest

    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.
     
    , Jul 31, 2005
    #1
    1. Advertising

  2. wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 31, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Yong
    Replies:
    0
    Views:
    558
    James Yong
    Sep 12, 2005
  2. CSharpner
    Replies:
    0
    Views:
    1,048
    CSharpner
    Apr 9, 2007
  3. Replies:
    3
    Views:
    2,770
  4. Sam Sungshik Kong

    require "mylibrary" doesn't work in ASP

    Sam Sungshik Kong, Jun 24, 2004, in forum: Ruby
    Replies:
    0
    Views:
    83
    Sam Sungshik Kong
    Jun 24, 2004
  5. NAKAMURA, Hiroshi
    Replies:
    0
    Views:
    137
    NAKAMURA, Hiroshi
    Jul 6, 2004
Loading...

Share This Page