bestbeans
bestbeans

Reputation: 21

use lib relative path not working

I have a perl script

#!/usr/bin/perl
use strict;
use lib 'lib';
use SOME_MOD;

that works on my old server. On the new server, it only works with absolute path, like

#!/usr/bin/perl
use strict;
use lib '/var/www/apps/myapp/lib';
use SOME_MOD;

What do i miss?

Upvotes: 0

Views: 1178

Answers (2)

bestbeans
bestbeans

Reputation: 21

mod_perl's cwd is not the same as the scripts location. Relative path resolution works when Webserver is configured with Perl CGI Script Support.

Upvotes: 1

ikegami
ikegami

Reputation: 385655

The directories in @INC is always relative the current working directory, but some web servers set the cwd to /. If you want a patch relative to the directory in which the script resides, you can use

use FindBin qw( $RealBin );
use lib "$RealBin/lib";

Alternatively, since the directory you want to add is $RealBin/lib or $RealBin/../lib, you can use mylib.

use mylib;

Upvotes: 3

Related Questions