如何找到Perl模块的安装位置?

Gal*_*axy 41 perl config module path

如何通过名称获取已安装的Perl模块的路径,例如Time::HiRes

我想要这只是因为我必须在SGE Grid Engine系统的不同节点上运行我的perl脚本.有时,甚至以其他用户名运行.

我可以使用CPAN.pm为自己安装软件包,但是对于没有文件夹上的chmod 666的其他用户来说安装起来并不容易.

jro*_*way 75

perl -MTime::HiRes -e 'print $INC{"Time/HiRes.pm"}' 要么 perldoc -l Time::HiRes

  • perldoc仅适用于那些已安装的人.第一个适用于所有人,但输入名称2次有点无聊. (3认同)
  • 在unixy系统上,我只是"找到Time/HiRes.pm". (2认同)
  • 但是,这并不能告诉您 Perl 在哪里查找文件。例如,我的 Perl 模块在 ~/perl/install 中。 (2认同)

bri*_*foy 21

您可以使用Perl附带的cpan工具获取模块详细信息:

$ cpan -D Time::HiRes
Time::HiRes
-------------------------------------------------------------------------
    High resolution time, sleep, and alarm
    J/JH/JHI/Time-HiRes-1.9719.tar.gz
    /usr/local/perls/perl-5.10.0/lib/5.10.0/darwin-2level/Time/HiRes.pm
    Installed: 1.9711
    CPAN:      1.9719  Not up to date
    Andrew Main (Zefram) (ZEFRAM)
    zefram@fysh.org
Run Code Online (Sandbox Code Playgroud)

它甚至适用于您尚未安装的模块:

$ cpan -D Win32::Process
Win32::Process
-------------------------------------------------------------------------
    Interface to Win32 Process functions
    J/JD/JDB/Win32-Process-0.14.tar.gz
    Installed: 
    CPAN:      0.14  Not up to date
    Jan Dubois (JDB)
    jand@activestate.com
Run Code Online (Sandbox Code Playgroud)

我想也许我需要像svn这样的XML选项.

  • 如果你写一个包如FOO :: Bar并把它放在`PERL5LIB`中怎么办? (5认同)
  • 我不明白你的评论。 (2认同)

mkl*_*nt0 17

我创建whichpm了一个跨平台的CLI(Linux,OSX,Window),它按模块(包)名称定位已安装的Perl模块,并可选择报告有关它们的信息,包括检测意外重复.

例子

# Locate the Data::Dumper module.
$ whichpm Data::Dumper
/usr/lib/perl/5.18/Data/Dumper.pm

# Locate the Data::Dumper module, and also print
# version information and core-module status.
$ whichpm -v Data::Dumper
Data::Dumper    2.145   core>=5.005 /usr/lib/perl/5.18/Data/Dumper.pm

# Locate the Data::Dumper module and open it in your system's default text
# editor.
$ whichpm -e Data::Dumper

# Look for accidental duplicates of the Foo::Bar module.
# Normally, only 1 path should be returned.
$ whichpm -a Foo::Bar
/usr/lib/perl/5.18/Foo/Bar.pm
./Foo/Bar.pm

# Print the paths of all installed modules.
$ whichpm -a
Run Code Online (Sandbox Code Playgroud)

安装

先决条件:安装了Perl v5.4.50或更高版本的Linux,OSXWindows.

从npm注册表安装

随着Node.js的io.js安装,安装软件包,如下所示:

[sudo] npm install whichpm -g
Run Code Online (Sandbox Code Playgroud)

手动安装(OSX和Linux)

  • 下载CLIwhichpm.
  • 使其可执行chmod +x whichpm.
  • 将其移动或符号链接到您的文件夹$PATH,例如/usr/local/bin(OSX)或/usr/bin(Linux).


Iva*_*uev 5

如果需要查找脚本实际使用的模块,可以使用perl debuggers M命令:

[ivan@server ~]$ perl -d your_script.pl
...

Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.

DB M
'AutoLoader.pm' => '5.60 from /usr/lib/perl5/5.8.8/AutoLoader.pm'
'Carp.pm' => '1.04 from /usr/lib/perl5/5.8.8/Carp.pm'
...

如果模块具有相同的名称但位于不同的文件夹中,这将有所帮助.

  • 这是最好的答案,因为它非常简单,不需要下载任何额外的软件。 (3认同)