2012-01-31 30 views
4

我已經下載並安裝了perl工具(格子工具)。 但它在我的本地目錄中。 雖然我運行它說無法找到Directed.pm(一個lib文件),這是我的本地目錄的lib文件夾中可用。 我希望它會設置正確的,如果我設置路徑變量。如果是這樣,我該如何設置它?格子工具路徑問題

回答

0

您需要將'lib'添加到目錄perl搜索模塊。你可以用-I標誌做到這一點:

perl -Ilib lattice-tool.pl 
+0

另一個選項是設置'$ PERLLIB'環境變量。 – reinierpost 2012-01-31 09:31:05

1

在我的劇本,我有以下的(我敢肯定可以改善,但迄今工作):

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

所以該腳本嘗試確定自己的目錄,然後告訴Perl在該目錄的lib子目錄中查找庫。

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 [...] 
2

對於使用lib中,你必須使用完整路徑,你不應該使用relativ路徑是這樣的。

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

情景:你的東西/斌/ prog.pl腳本,你的lib是什麼/ lib目錄/ lib.pm。

如果使用relativ路徑,你應該打電話給你的程序是這樣的:

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

如果你想使用relativ路徑,使用FindBin找到你的當前位置:

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

然後你可以從任何地方調用你的程序,它總能找到它自己的lib realtiv。

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