我该如何“使用"?目录中没有@INC的Perl模块? [英] How do I "use" a Perl module in a directory not in @INC?

查看:79
本文介绍了我该如何“使用"?目录中没有@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

我快疯了!怎么了?

推荐答案

use在编译时进行,因此可以使用:

use takes place at compile-time, so this would work:

BEGIN {push @INC, '..'}
use EPMS;

但是更好的解决方案是use 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆