in reply to Using variables within use and package statement

See perldoc -m lib (use lib 'DIR').

In your case, you'd use something like:

use lib $ENV{'FOLDER'}; use gui::skills_gui; use db::skills_db;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Using variables within use and package statement
by perl_devel (Friar) on Oct 06, 2005 at 06:47 UTC
    This solution works for use statments , But for package
    name is there an option ?

    package newpath::gui::newfile;

    can newpath be replaced with any variables in defining
    package names?

      Unless I am misunderstanding you, you shouldn't need to do that?

      The 'normal' way of doing things is:

      --- file \this\path\gui\skills_gui.pm -- package skills_gui; ... ---------------------------------------- --- file \this\path\db\skills_db.pm -- package skills_db; ... ---------------------------------------= --- file \that\path\gui\skills_gui.pm -- package skills_gui; ... ---------------------------------------- --- file \that\path\db\skills_db.pm -- package skills_db; ... ---------------------------------------=

      And in the calling script have

      ---- File: \some\other\path\yourscript.pl --- use lib $ENV{LIB_PATH}; use gui::skills_gui; use db::skills_db; ....

      For one run of the script set LIB_PATH=\this\path\ and it will use \this\path\gui\skills_gui.pm and \this\path\db\skills_db.pm
      and for another run you'd set LIB_PATH=\that\path\ and it will use \that\path\gui\skills_gui.pm and \that\path\db\skills_db.pm.

      So the one script unchanged will use either set of modules depending upon the setting of the environment variable.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

      No (unless you want to rewrite your symbol tables, but don't do that).

      This solution works for use statments , But for package name is there an option ?
      None that I know (IIUC). That is: none that is not in the real of brainf***ed solutions. But you don't want to do that: just either use OO syntax directly or export whatever you need to, if you prefer a functional UI.