v_melnik has asked for the wisdom of the Perl Monks concerning the following question:
Dear colleagues,
The script doesn't know how deep in the directory tree it lies: in '/***/monkeyman/bin' or in '/***/monkeyman/bin/test', but it needs to know it as it needs to load modules from /***/monkeyman/lib.
It seems it can't perform any regex matching before the compiler loads all libraries, am I right? Because, as I see, it doesn't...
use FindBin qw($Bin); if($Bin =~ /^(\/.+\/monkeyman\/bin)(\/.+)?/) { use lib("$1/lib"); } use MonkeyMan;
Leads to:
Use of uninitialized value $1 in concatenation (.) or string at ./someutil.pl line 9. Can't locate MonkeyMan.pm in @INC (@INC contains: /lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./someutil.pl line 12. BEGIN failed--compilation aborted at ./someutil.pl line 12.
As I see, the "use lib" line actually works: it adds "/lib" to @INC, but why doesn't it substitute $1?
How would you solve it? Is there any elegant way to find the root directory before loading libraries if the script doesn't know how deep in the directory tree it is?
Lots of thanks to all.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Calculations before using lib;
by choroba (Cardinal) on Aug 04, 2014 at 15:06 UTC | |
by ikegami (Patriarch) on Aug 04, 2014 at 16:10 UTC | |
by v_melnik (Scribe) on Aug 04, 2014 at 15:09 UTC | |
by afoken (Chancellor) on Aug 05, 2014 at 04:40 UTC | |
Re: Calculations before using lib; (FindLib)
by tye (Sage) on Aug 04, 2014 at 16:48 UTC | |
Re: Calculations before using lib;
by ikegami (Patriarch) on Aug 04, 2014 at 16:11 UTC | |
Re: Calculations before using lib;
by v_melnik (Scribe) on Aug 06, 2014 at 11:31 UTC |