Perl 的 FindBin 行为的改变

发布于 2024-11-19 23:42:51 字数 183 浏览 4 评论 0原文

我有一组使用 FindBin 模块的 Perl 脚本。脚本使用一些数据文件,并希望在 $FindBin::Bin/../share/somedir/ 中找到它们。我正在自定义安装,因此这些文件现在存在于 /some/other/share/dir/ 中。有什么方法可以使用环境变量之类的东西来自定义 FindBin 的行为吗?

I've got a collection of Perl scripts which use the FindBin module. There are some data files which the scripts use, and are expecting to find them in $FindBin::Bin/../share/somedir/. I'm customizing the installation so those files now exist is /some/other/share/dir/. Is there any way to customize the behaviour of FindBin with something like, say, an environment variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扛起拖把扫天下 2024-11-26 23:42:51

我认为您不能使用 FindBin 模块解决这个问题,因为它旨在解决特定问题:定位原始 perl 脚本的目录
您应该实现自己的模块来获取配置参数。这看起来像:

package MyConfig;
use strict; use warnings;
use FindBin;

sub get_data_folder {
    return ($ENV{'DEV_ENVIROMENT'} ?  ## create this variable in your development
        $FindBin::Bin."/../share/somedir/" :
        "/some/other/share/dir/"
    );
}
1;

这将允许您在一处控制所有配置路径。但您需要更改现有代码。

I don't think you can solve this problem with FindBin module, because it's designed to solve particular problem: locate directory of original perl script.
You should implement your own module to getting configuration parameters. This can look like:

package MyConfig;
use strict; use warnings;
use FindBin;

sub get_data_folder {
    return ($ENV{'DEV_ENVIROMENT'} ?  ## create this variable in your development
        $FindBin::Bin."/../share/somedir/" :
        "/some/other/share/dir/"
    );
}
1;

This will allow you to control all your configuration path in one place. But you'll need to change exists code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文