简体   繁体   English

尝试使用库Perl时在库名称中使用变量

[英]Using a variable in a library name when trying to use a library perl

I want my library name to change (I have reasons), but when I use a variable in the library path, it can't seem to find it.....Can't locate APOE.pm in @INC 我想更改库名(有原因),但是当我在库路径中使用变量时,似乎无法找到它.....在@INC中找不到APOE.pm

my ($plugin_name) = @ARGV; 
use lib("/usr/share/perl/5.10.1/$plugin_name");
use APOE qw(callAPOE);

Is this not possible? 这不可能吗?

Edit: $plugin_name = "AIB-TorrentPanel-v2.00"; 编辑:$ plugin_name =“ AIB-TorrentPanel-v2.00”; AND module name is APOE.pm AND模块名称为APOE.pm

You could simply write: 您可以简单地写:

use lib "/usr/share/perl/5.10.1/$ARGV[0]";

or, if you need to do something more complicated to set up the directory name than your example code shows: 或者,如果您需要做的事来设置目录名,而不是示例代码所示:

my $plugin_name;
BEGIN {
    ($plugin_name) = @ARGV;
}
use lib "/usr/share/perl/5.10.1/$plugin_name";

Your my ($plugin_name) = @ARGV; 您的my ($plugin_name) = @ARGV; will run at run-time, it is too late for lib . 将在运行时运行,对于lib来说为时已晚。 According to the manual of lib , use lib LIST; 根据lib的手册use lib LIST; is almost equals 几乎等于

BEGIN { unshift(@INC, LIST) }

but your $plugin_name would not be available at that time. 但是您的$plugin_name当时无法使用。

However, you could replace your use with a require , like this: 但是,您可以将您的use替换为require ,如下所示:

my ($plugin_name) = @ARGV;
require "/usr/share/perl/5.10.1/$plugin_name/APOE.pm";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM