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

I am running several scripts (using DBI) succesfully in a browser and am retrieving data from a mysql db.
However when i execute the same script at the command promt it cant seem to locate the DBI module. Does anyone know why this could be?
Here is the error at the command prompt in case you wanted to see it.
Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib/perl5/5.6.1 +/i686-linu x /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/i686 +-linux /us r/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at + cat_ed.pl line 11. BEGIN failed--compilation aborted at cat_ed.pl line 11.


THanks, costas

Replies are listed 'Best First'.
Re: works in browser but not in prompt
by MZSanford (Curate) on Jul 23, 2001 at 14:16 UTC
    The problem lies in your path. The user the webserver is running as (probably 'nobody') is using a direcoty from with the modules can be seen, but the user from which you are running cannot. It appears this is a unix machine, so doing find /usr -name "DBI.pm" will ler you know where the module lives, and you can manipulate your environment (or @INC) accordingly.
    remeber the immortal word's of Socrates who said, "I drank what ?"
Re: works in browser but not in prompt
by tachyon (Chancellor) on Jul 23, 2001 at 15:05 UTC

    Assuming you can access a command prompt (which it seems you can) type

    which DBI.pm

    Once you have the path add either of these to your CGI as a quick fix.

    use lib "$path"; # or you can BEGIN { push @INC, $path }

    where $path is the path reported by which. This will add this path to @INC just before your script runs, allowing it to find the DBI module. I believe use lib is the preferred method but either will generally work.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Or on the command line
      perl -Mlib=/path/to/dbi script.pl
      Which effectively puts a use lib at the start of your program.
Re: works in browser but not in prompt
by converter (Priest) on Jul 23, 2001 at 18:39 UTC

    The PATH string in the environment has nothing to do with the set of directories perl searches for modules (@INC). The default values assigned to @INC are determined when Perl is compiled.

    Watch what happens when we set PATH to "/usr/bin":

    $ PATH=/usr/bin perl -e 'use DBI; print qq(\nDBI pathname: $INC{"DBI.p +m"}\n)' DBI pathname: /usr/lib/perl5/site_perl/5.6.1/i686-linux/DBI.pm

    I'd say chances are pretty good that you're running one build of perl from the command line and the server is running another; probably two different versions (clue: not many production servers are going to be running 5.6.1). DBI was installed for the build that the server is running, but not for the build you're running. The solution is probably going to be to install DBI or have an admin install it for you, so that your build has access to it.

    conv