格子工具路径问题

时间:2012-01-31 08:42:43

标签: perl

我已经下载并安装了一个perl工具(网格工具)。 但它在我的本地目录中。 我正在运行时说无法找到我的本地目录的lib文件夹中可用的Directed.pm(一个lib文件)。 我希望如果设置路径变量,它将被设置为正确。如果是这样,我该如何设置呢?

4 个答案:

答案 0 :(得分:2)

对于使用lib,你必须使用完整路径,你不应该使用这样的相对路径。

use '../lib';#not working in all times.

场景:您的脚本在/ bin / prog.pl中,您的lib是/ lib / lib.pm。

如果您使用相对路径,则应该像这样调用您的程序:

cd something/bin/ && ./prog.pl

如果您想使用相对路径,请使用FindBin查找当前路径:

use FindBin;
use lib "$FindBin::Bin/../lib";#your lib realitv to your script
use lib $FindBin::Bin;#your current script full path

然后你可以从任何地方调用你的程序,它总能找到它自己的lib。

cd ~   
something/bin/prog.pl# ti will use the correct lib

答案 1 :(得分:1)

在我的脚本中,我有以下内容(我确信可以改进,但到目前为止已经有效):

my $mydir;  BEGIN { ($mydir) = ($0 =~ m#(.*)[/\\]#) or $mydir = '.'; }
use lib "$mydir/lib";

因此脚本会尝试确定自己的目录,然后告诉Perl在该目录的lib子目录中查找库。

答案 2 :(得分:0)

您需要将'lib'添加到perl搜索模块的目录中。您可以使用-I标志执行此操作:

 perl -Ilib lattice-tool.pl

答案 3 :(得分:0)

使用lib

use lib 'lib';

lib还检查lib下的体系结构特定子目录,以确保加载机器相关的库。

编辑:请注意,传递给lib的目录是相对于当前工作目录的,因此如果您想从其他位置执行脚本,则应使用use lib '/home/user1126070/lib'

来自perlvar

The array @INC contains the list of places that the do EXPR , require, or use
constructs look for their library files. It initially consists of the arguments
to any -I command-line switches, followed by the default Perl library, probably
/usr/local/lib/perl, followed by ".", to represent the current directory. ("."
will not be appended if taint checks are enabled, either by -T or by -t .) If you
need to modify this at runtime, you should use the use lib pragma to get the
machine-dependent library properly loaded [...]