Click here to get back home

FindBin question

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
FindBin question Ronny 12-13-2006
Posted by Ronny on December 13, 2006, 7:56 am
Please log in for more thread options


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");

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


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.


Posted by Ronny on December 14, 2006, 4:11 am
Please log in for more thread options


> Perhaps try this in newprog.pl:
>
> $ENV =~ s;
> $ENV =~ s;

Actually, if you look at my posting, you see that PATH *is* set so that
it
points to the myutil directory. Strangely this is not sufficient to
make
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.

Ronald


Similar ThreadsPosted
FindBin cannot chdir back problem July 12, 2005, 5:23 pm
DBI question November 5, 2004, 4:28 pm
Newbie Question January 3, 2005, 4:11 pm
LWP question on windows98 October 7, 2004, 8:19 pm
Question to WIN32::OLE October 14, 2004, 11:34 am
Simple question September 15, 2005, 4:17 am
Getopt::Std question September 7, 2005, 9:42 am
Question regarding databases.. November 18, 2005, 9:41 am
Module Question October 25, 2004, 11:42 am
A question of name space October 31, 2004, 2:55 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap