Linux perl 库路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12320543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:17:31  来源:igfitidea点击:

perl library path

linuxperlunix

提问by Elb

I need to retrieve the path where the perl libraries Statistics and Distributions are located. The path is necessary to run the script. I'm on a computer cluster. Can anyone help me?

我需要检索 perl 库统计和分布所在的路径。该路径是运行脚本所必需的。我在一个计算机集群上。谁能帮我?

Thanks

谢谢

采纳答案by Ben Deutsch

This answer assumes that the module is in fact installed, but not in a place that perlis looking for.

此答案假定该模块实际上已安装,但未安装在perl正在查找的位置。

Generally, the Perl module Statistics::Distributionswill be contained in a file called Statistics/Distributions.pm. On Linux and similar systems, one can search for these files quickly with the locatecommand:

通常,Perl 模块Statistics::Distributions将包含在名为Statistics/Distributions.pm. 在 Linux 和类似系统上,可以使用以下locate命令快速搜索这些文件:

locate Statistics/Distributions.pm

If it is installed, locatewill spit out a line similar to

如果安装了,locate会吐出类似的一行

/opt/my_perl/lib/Statistics/Distributions.pm

You can then instruct the perlinterpreter to look in this path, too, in various ways. One is to define the environment variable PERL5LIB, i.e. from bash:

然后,您也可以指示perl解释器以各种方式查看此路径。一种是定义环境变量PERL5LIB,即来自bash

prompt> PERL5LIB=/opt/my_perl/lib/ ./myscript.pl

Or you can use the perl -Iswitch:

或者您可以使用perl -I开关:

prompt> perl -I/opt/my_perl/lib/ ./myscript.pl

Or you can modify the script to use lib; there is more than one way to do it ;-)

或者您可以将脚本修改为use lib; 有不止一种方法可以做到;-)

回答by zigdon

If you mean you need the path of a module you're using in a program, that's stored in %INC:

如果你的意思是你需要你在程序中使用的模块的路径,它存储在%INC

$ perl -MLWP::Simple -le 'print $INC{"LWP/Simple.pm"}'
/usr/share/perl5/LWP/Simple.pm

回答by ikegami

"Can't locate XXX in @INC" usually indicates the module isn't installed. Have you installed Statistics::Distributions?

Can't locate XXX in @INC”通常表示未安装模块。您是否安装了Statistics::Distributions

cpan Statistics::Distributions

回答by Sergey Sinkovskiy

perldoc -m Your::Module- displays source of module

perldoc -m Your::Module- 显示模块的来源

perldoc -l Your::Module- display path to library if it's installed and found in PERL5LIB, -I, @INC, etc.

perldoc -l Your::Module- 如果已安装并在 PERL5LIB、-I、@INC 等中找到,则显示库的路径。

回答by leonardo

I had the same trouble and it can be fixed both ways:

我遇到了同样的问题,可以通过两种方式解决:

1) by running the comand perl -I/blabla/folder_your_module_is_installed/blib/lib/ ./script.pl

1) 通过运行命令 perl -I/blabla/folder_your_module_is_installed/blib/lib/ ./script.pl

for dummies like me, it is important to note that the end of the path is "lib/", not "lib/Other_folder/". Because there are more folders after it.

对于像我这样的傻瓜,重要的是要注意路径的结尾是“lib/”,而不是“lib/Other_folder/”。因为后面有更多的文件夹。

2) inside the script you can write: use lib 'blabla/folder_your_module_is_installed/blib/lib/';

2)在脚本中你可以写:使用 lib 'blabla/folder_your_module_is_installed/blib/lib/';

save and run perl scripit.pl

保存并运行 perl script.pl