use lib relative path not working

最后都变了- 提交于 2019-12-13 04:13:44

问题


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?


回答1:


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;



回答2:


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.



来源:https://stackoverflow.com/questions/19096127/use-lib-relative-path-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!