|
Posted by Mumia W.o on December 13, 2006, 7:12 pm
Please log in for more thread options
On 12/13/2006 06:56 AM, Ronny wrote:
> I've a program myutil.pl, which uses FindBin to locate other
> modules, in the following way:
>
> #!/usr/local/bin/perl
> # This is file myutil.pl !
> use warnings;
> use strict;
> use FindBin;
> 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
> program,
> newprog.pl, in a different directory, which is supposed to use
> myutil.pl above
> 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
> in
> $ENV, but in newprog.pl's @INC
>
> (I know that the second assumption is a bit esoteric, but in this
> particular case
> this is how it is).
>
> Here is the excerpt from newprog.pl which invokes myutil.pl:
>
> #!/usr/local/bin/perl
> # This is file newprog.pl !
> use lib "....";
> ......
> # Temporarily append @INC to PATH when calling myutil.pl
> system('PATH=$PATH:'.join(':',@INC)." myutil.pl");
>
Perhaps try this in newprog.pl:
$ENV =~ s;
$ENV =~ s;
system 'myutil.pl';
> Indeed, myutil.pl gets invoked, as expected, but then, myutil.pl claims
> that
> it is unable to find the module Support.pm . A look at @INC reveals
> that
> the directory of newprog.pl is incorporated in the @INC path, but not
> that
> of myutil.pl.
>
> 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
> this:
>
> $HOME/foo/myutil.pl
> $HOME/foo/Support.pm
> $HOME/bar/newprog.pl
>
> 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,
> so that
> 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?
>
> Ronald
>
In addition to the above I wrote, you could also create a shell script
that sets PATH and PERL5INC before invoking newprog.pl.
|