2017-07-06 54 views
0

我下載了一個用於生成語言模型的perl腳本(http://www.speech.cs.cmu.edu/tools/download/quick_lm.pl)。perl <file.pl>被執行完全沒有輸出

當我做perl quick_lm.pl,它只是終止。根本沒有輸出。

  • 是的,我有perl安裝和perl -v完美的作品。

  • 我做了一個簡單的hello-world perl腳本,它執行得很好。 [附着在結束]

  • 所以,我在quick_lm.pl的第一行包含print "hello";,並試圖perl quick_lm.pl,仍然沒有任何反應。

我甚至嘗試使用chmod 777 quick_lm.plquick_lm.pl所有權限。現在,當我做./quick_lm.pl它給出了一個錯誤:

-bash: ./quick_lm.pl: /usr/local/bin/perl: bad interpreter: No such file or directory 

我搜索這個錯誤,幾乎所有的解決方案,指着窗戶CLRF,但與他們不同,我沒有在/usr/local/bin/perl^M。此外,仍然perl quick_lm.pl應該工作,對吧?


[bash.log]

[email protected]:~/dictionary$ perl quick_lm.pl 
[email protected]:~/dictionary$ perl quick_lm.pl -s words.txt 
[email protected]:~/dictionary$ nano quick_lm.pl 
[email protected]:~/dictionary$ perl quick_lm.pl -s words.txt 
[email protected]:~/dictionary$ chmod 777 quick_lm.pl 
[email protected]:~/dictionary$ ./quick_lm.pl 
-bash: ./quick_lm.pl: /usr/local/bin/perl: bad interpreter: No such file or directory 
[email protected]:~/dictionary$ cat new.pl 
#!/usr/bin/perl -w 
use strict; 

print "Hello World\n"; 
[email protected]:~/dictionary$ perl new.pl 
Hello World 
[email protected]:~/dictionary$ 

[在quick_lm.pl開頭添加print和它減少到該問題的一個最小的,可運行的示範之後。]

#!/usr/local/bin/perl -w 
=POD 

...license... 

=END 

use Getopt::Std; 

print "hello world"; 
$VERBOSE = 1; 

sub handler { local($sig) = @_; 
      print STDERR "quick_lm caught a SIG$sig -- dying\n"; 

      exit(0); 
     } 
foreach (qw(XCPU KILL TERM STOP)) { $SIG{$_} = \&handler; } 

這不是完整的腳本,完整的腳本是在第一行中提到的鏈接。我不確定它是否與我的perl配置文件相關。正如你可能已經猜到的,我對perl沒有太多的想法。

我很欣賞你的時間和幫助:)

+1

你的'perl'安裝在哪裏?當你輸入'command -v perl'時你會得到什麼?也許它是'/ usr/bin/perl'而不是'/ usr/local/bin/perl'? –

+0

@EricRenouf你對這部分是正確的。它確實安裝在'/ usr/bin/perl'上。我將文件編輯爲'#!/ usr/bin/perl -w',並且它不會給出錯誤,而是再次輸出。 –

+0

我現在不能複製你的結果,如果我複製並粘貼上面的腳本我會得到一個警告,然後「hello world」,雖然沒有一個新行,所以它可能是「隱藏」旁邊的提示 –

回答

2

-bash: ./quick_lm.pl: /usr/local/bin/perl: bad interpreter: No such file or directory

更換/usr/local/bin/perl用正確的路徑perl。這個路徑可以從

perl -le'print $^X' 

它簡單地終止而獲得。根本沒有輸出。

=pod指令指示內聯文檔的開始( 「POD」)。 =cut標誌着POD塊的結束。

程序不正確地使用=END而不是=cut標記POD塊的結束,使Perl的認爲整個程序是一個很大的評論..更換=END=cut

+0

需要注意的是,它是區分大小寫的。 '= CUT'不起作用,但'= cut'起作用! –

+0

@Saurabh Shrivastava,是的,但這與問題無關。該問題中的程序使用'= END'而不是'= cut'。 – ikegami

+0

我不是批評,只是評論,以通知未來的求職者! :)感謝你,我在沒有篡改許可證的情況下工作。 –