如何从相对位置使用 Perl 模块? [英] How do I use a Perl module from a relative location?

查看:25
本文介绍了如何从相对位置使用 Perl 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 foo 的目录,其中我有 libbin.bin 中的脚本需要 lib 中的东西.我做这样的事情:

I have a dir called foo, and in that I have lib and bin. The scripts in bin need stuff in lib. I do something like this:

#!perl
use strict;
use warnings;
use lib '../lib';
use Foo; # <-- comes from lib

但这意味着我必须在 bin 目录中才能运行脚本.当然还有更好的方法.这样做的正确方法是什么?

But that means I have to be in the bin dir to run the script. Surely there is a better way. What's the Right Way to do this?

推荐答案

标准FindBin 模块做你想做的事.

The standard FindBin module does what you want.

use FindBin;
use lib "$FindBin::Bin/../lib";

perldoc FindBin 了解更多.

这篇关于如何从相对位置使用 Perl 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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