Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- FindBin question
December 13, 2006, 12:56 pm
rate this thread
I've a program myutil.pl, which uses FindBin to locate other
modules, in the following way:
# This is file myutil.pl !
use lib "$FindBin::Bin";
# Support.pm is in the same directory as myutil.pl
use Support; # <---- found via FindBin magic
This worked fine and I was very happy with this. Now I have a different
newprog.pl, in a different directory, which is supposed to use
under the following assumptions:
- myutil.pl should be called via a call to system("...")
- It is known that myutil.pl happens to be in a directory which is not
$ENV, but in newprog.pl's @INC
(I know that the second assumption is a bit esoteric, but in this
this is how it is).
Here is the excerpt from newprog.pl which invokes myutil.pl:
# This is file newprog.pl !
use lib "....";
# Temporarily append @INC to PATH when calling myutil.pl
Indeed, myutil.pl gets invoked, as expected, but then, myutil.pl claims
it is unable to find the module Support.pm . A look at @INC reveals
the directory of newprog.pl is incorporated in the @INC path, but not
Maybe I misunderstood something in the way FindBin works. How do
I deal with this situation? In a short way, the files are located like
with the following conditions:
- newprog.pl calls myutil.pl via system().
- myutil.pl uses Support.pm.
- The use statement in myutil.pl should not mention the path $HOME/foo,
I can easily move the files around to different locations.
- The use statement in newprog.pl *does* mention the path $HOME/foo (no
need to be flexible here)
- $HOME/bar/newprog.pl and $HOME/foo/myutil.pl should both be callable
from the command line
Any ideas how to do this?
Re: FindBin question
Actually, if you look at my posting, you see that PATH *is* set so that
points to the myutil directory. Strangely this is not sufficient to
FindBin the module in this particular case.
Extending PERL5LIB would indeed solve the problem, but it would not
explain why FindBin fails to do its job in my example.