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

I have the following code which works fine on linux with apache:
#!/usr/bin/perl -w use strict; use user_login; use user_logout;

user_login/out are my own .pm's in the same cgi-bin directory that the cgi script is running from. For some reason I get the message that perl cannot find the modules when running on Windows with IIS (not in @INC).

How do i call a module in windows that is in the same directory as the cgi that is running?

Replies are listed 'Best First'.
Re: Modules on Windows/IIS
by Steve_p (Priest) on Sep 30, 2002 at 18:56 UTC

    Try adding

    use lib ".";

    I don't think, however, that placing your modules in an executable directory is a good thing. Especially if there is actual login information in those modules. Often, since a .pm file will not have a proper MIME type entered for the webserver, your webserver will allow users to pull down the code as text. I would find a different directory to place your libraries outside of the webserver root so they are more secure.

Re: Modules on Windows/IIS
by Enlil (Parson) on Sep 30, 2002 at 18:54 UTC
    you can at the top add the following line near the beginning:

     use lib "directory_to_pm";

    or

    my $directory_name = "directory_to_pm"; push @INC, $directory_name;

    -ENLIL

      Which of the following lines do you think will be executed first?
      my $directory_name = "directory_to_pm"; push @INC, $directory_name; use MyModule;

      -Blake

Re: Modules on Windows/IIS
by Jenda (Abbot) on Sep 30, 2002 at 19:40 UTC
    1. It's not the best idea to place the modules in the same directory as the CGI. Especialy if you use IIS.
      Unless you instruct the server to treat .pm special, the modules will be easily downloadable by anyone.
      It's better to create a private library directory somewhere outside the web root and add
      use lib 'c:\path\to\the\directory';
      on top of your scripts or to set the PERL5LIB system variable to include that directory.
       
    2. Under IIS the current directory is NOT the directory where the script is located, but the web root directory. If you insist on placing them alongside the CGI, use
      use FindBin qw($Bin); use lib $Bin;
      to add the script's directory to @INC.
    3. Jenda

Re: Modules on Windows/IIS
by nutshell (Beadle) on Sep 30, 2002 at 20:09 UTC
    Add this on the line before you call the modules:
    BEGIN { unshift @INC, $1 if $0 =~ m!(.*[/\\])!; }