我如何“使用"不在@INC 中的目录中的 Perl 模块? [英] How do I "use" a Perl module in a directory not in @INC?
本文介绍了我如何“使用"不在@INC 中的目录中的 Perl 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的脚本的父目录中有一个模块,我想使用"它.
I have a module in the parent directory of my script and I would like to 'use' it.
如果我这样做
use '../Foo.pm';
我收到语法错误.
我尝试这样做:
push @INC, '..';
use EPMS;
和..显然没有出现在@INC
and .. apparently doesn't show up in @INC
我快疯了!这里有什么问题吗?
I'm going crazy! What's wrong here?
推荐答案
use
发生在编译时,所以这会起作用:
use
takes place at compile-time, so this would work:
BEGIN {push @INC, '..'}
use EPMS;
但更好的解决方案是使用lib
,这是编写上述内容的更好方式:
But the better solution is to use lib
, which is a nicer way of writing the above:
use lib '..';
use EPMS;
如果您从不同的目录运行,建议使用 FindBin
:
In case you are running from a different directory, though, the use of FindBin
is recommended:
use FindBin; # locate this script
use lib "$FindBin::RealBin/.."; # use the parent directory
use EPMS;
这篇关于我如何“使用"不在@INC 中的目录中的 Perl 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文