[Canberra-pm] do read-local.config

Jacinta Richardson jarich at perltraining.com.au
Wed Mar 29 22:31:43 PST 2006


You can always use package variables:

------ config.pl

$::etc_path = "/some/path";

------ main.pl

use strict;
BEGIN {
         do "./config.pl";
}
use lib "$::etc_path/lib";

------------------------------------

Which is something I found useful for a bunch of CGI scripts which all needed to
know where the lib was, except that lib's location varied depending on whether
it was production or development.


Lexical variables exist only for their enclosing block.  The biggest enclosing
block is a file, so had $etc_path been declared with "my" there would be no
result after calling "do".

Obviously there are drawbacks to using package variables, they never go out of
scope.  If you need something that is even a little bit more complicated than
what I wrote above, I'd suggest moving to something like Config::General rather
than "do"ing a file.

All the best,

     Jacinta

-- 
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |




More information about the Canberra-pm mailing list