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

查看:130
本文介绍了如何从相对位置使用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天全站免登陆