kgrubb has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run a perl program from Autosys (a job scheduler) and it is having some major problems with the @INC array. I keep getting the following error:

"Can't locate Net/FTP.pm in @INC at c:\usr\local\adm\unitrex_eod.pl line 42. BEGIN failed--compilation aborted at c:\usr\local\adm\unitrex_eod.pl line 42."

I've tried using the "Push @INC" , the "use" statment, and the "-I" in the shebang and nothing seems to work.

Questions:
1) If I use the shebang -I or the "Push @INC" statements, do I still need the USE statement?
2) Do I call the module a different way if I use the shebang or begin solutions?

Any thoughts is greatly appreciated, I've been spinning my wheels on this for awhile.

Here is the exact code if you need it:
#!c:/perl/perl.exe -w use Net::FTP; use MSSQL::Sqllib qw(:DEFAULT :rowstyles); use Net::SMTP; use strict;

Replies are listed 'Best First'.
Re: @INC Question
by vek (Prior) on Feb 06, 2002 at 15:24 UTC
    It looks like you don't have Net::FTP installed on that box hence the "Can't locate..." error. If you are using ActivePerl you can use PPM to install that module.
    ppm>install Net::FTP
    If you do have it installed but it's in a "non-standard" directory you'll have to tell perl to add that dir to @INC:
    use lib 'c:/path-to/the-dir/that-contains-Net-Ftp';
Re: @INC Question
by dash2 (Hermit) on Feb 06, 2002 at 16:47 UTC
    The reason push @INC doesn't work is probably that it isn't in a BEGIN{} block. use works at compile time, so by the time you change @INC, it's too late - you already died. Do
    BEGIN{push @INC, '/new/library/path'}
    before your use. (Better still, use lib - but I thought you might want to understand the internals.)

    dave hj~

Re: @INC Question
by Biker (Priest) on Feb 06, 2002 at 15:30 UTC

    For starters:
    Write a small Perl script that doesn't use anything at all, but that prints out the contents of @INC for you. Run this by AutoSys and see what is your current @INC in the target AutoSys environment.

    Then, manually verify if you really do have Net::FTP somewhere in the paths from @INC.

    "Livet är hårt" sa bonden.
    "Grymt" sa grisen...

      For some reason Autosys was adding it's environment to the @INC array, meaning the array included c:\Autosys.INSTANCE\Perl\lib instead of the normal c:\Perl\lib.

      If anyone using Autosys in the future has this problem I simply had to install perl under the Autosys.INSTANCE directory. (I know I cheated but it seemed the easier way). Thanks again for your help.
Re: @INC Question
by iakobski (Pilgrim) on Feb 06, 2002 at 15:26 UTC
    @INC holds the paths that Perl searches to find the modules. The modules are specified with use. So be clear that they are separate issues you are talking about.

    1. The error you get shows that Net::FTP is not in the standard @INC path. Have you installed the module? I don't know if it is now in the standard distribution but it didn't used to be.

    2. If you have installed it but not to the standard directory, you should add that directory to @INC. Do not push to @INC, rather do this:

    use lib '/export/local/perl'
    Before you call use Net::FTP

    -- iakobski

Re: @INC Question
by BazB (Priest) on Feb 06, 2002 at 15:33 UTC

    If you're not aware already, @INC is the array that contains the directories perl will search through to find modules.

    If you get an error like the one you're seeing, it's likely to be one of the following:

    • The module is not installed
    • The module is installed, but is in a nonstandard location, or somewhere not listed in @INC

    This can be fixed by either installing the module, or adding the line use lib '/path/to/module/'; at the top of your script (obviously entering the right path).

    Hope that helps.

    BazB.

    Update: Another post of mine that duplicates others. *Sigh*
    Not deliberate, honest - phone rings before I hit submit!