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

Discussion in 'Perl Misc' started by doolittle, Oct 27, 2006.

  1. doolittle

    doolittle Guest

    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
    doolittle, Oct 27, 2006
    #1
    1. Advertising

  2. doolittle

    Sisyphus Guest

    "doolittle" <> wrote in message
    ..
    ..
    >
    > 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
    Sisyphus, Oct 27, 2006
    #2
    1. Advertising

  3. doolittle

    doolittle Guest

    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
    doolittle, Oct 27, 2006
    #3
  4. doolittle wrote:
    > 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

    --
    brian
    Brian Helterline, Oct 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vittorio

    Boxed Perl or ActiveState Perl?

    Vittorio, Apr 1, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    178
    GreenLight
    Apr 2, 2004
  2. Jake Wiley
    Replies:
    14
    Views:
    287
  3. Dilbert
    Replies:
    1
    Views:
    114
    Dilbert
    Dec 20, 2009
  4. Perl Junkie
    Replies:
    5
    Views:
    142
    Perl Junkie
    Sep 7, 2010
  5. Dilbert
    Replies:
    0
    Views:
    831
    Dilbert
    Nov 10, 2011
Loading...

Share This Page