activestate perl via shell() on XP, module location problem

D

doolittle

Hi,

I have a perl program - mymodscript.pl - which works from the command
line on XP, but when i try to run it from visual basic with the
shell("perl mymodscript.pl") command, it complains that it can't find
mymodule.pm.

mymodule.pm is one that i have written (and which mymodscript.pl
needs), and put in the same directory as mymodscript.pl.

I know that the shell command works because if i change mymodscript.pl
so that it doesn't need mymodule.pm, it works both from the command
line and from visual basic using shell("perl myscript.pl")

I have tried using perl -I path-to-my-modules, but that didn't work.

Does anyone have an explanation?

thanks
 
S

Sisyphus

..
..
mymodule.pm is one that i have written (and which mymodscript.pl
needs), and put in the same directory as mymodscript.pl.

There's a bit of a trap there. The fact that 'mymodule.pm' is in the same
directory as 'mymodscript.pl' doesn't really count for much.
What *is* important is that 'mymodule.pm' is in @INC.

On Win32, that will *typically* (but not necessarily) mean that
'mymodule.pm' has to be in either 'C:\perl\lib', 'C:\perl\site\lib' or the
cwd (current working directory).

To check all of this, your 'mymodscript.pl' could (untested):

use Cwd;
print getcwd, "\n";
for(@INC) { print "$_\n" unless $_ eq '.'}

If 'mymodule.pm' is not located in *any* of the specified locations, then
that's your problem.

Cheers,
Rob
 
D

doolittle

Thanks for the suggestion, i think i understand (a bit of) whats going
on:

The shell("mymodscript.pl") command runs in

C:/Documents and Settings/ibm/My Documents

this 'works' somehow although mymodscript.pl isn't in this directory,
its in

C:/Documents and Settings/ibm/My Documents/perl

which is where the modules are, which is why perl can't find them.

So i could put the module in C:/Perl/site/lib, or alter @INC to include

C:/Documents and Settings/ibm/My Documents/perl
 
B

Brian Helterline

doolittle said:
Thanks for the suggestion, i think i understand (a bit of) whats going
on:

The shell("mymodscript.pl") command runs in

C:/Documents and Settings/ibm/My Documents

this 'works' somehow although mymodscript.pl isn't in this directory,
its in

C:/Documents and Settings/ibm/My Documents/perl

which is where the modules are, which is why perl can't find them.

So i could put the module in C:/Perl/site/lib, or alter @INC to include

C:/Documents and Settings/ibm/My Documents/perl

Another method to use for modules you don't have in @INC is:

# yoursript.pl
use FindBin;
use lib $FindBin::Bin; # adds location of script to @INC
use yourmodule;


This method requires yourmodule.pm be in the same directory as
yourscript.pl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,328
Latest member
66Teonna9

Latest Threads

Top