2012-10-29 64 views
4

連接到MongoDB的時候我試圖運行簡單「的MongoDB:教程」教程:編譯錯誤在Perl

http://search.cpan.org/dist/MongoDB/lib/MongoDB/Tutorial.pod

我的目標是從一個Perl腳本連接到MongoDB數據庫。我已經使用cpanm安裝的MongoDB:

$ sudo cpanm MongoDB 
MongoDB is up to date. (0.501.1) 

我創建了一個簡單的Perl腳本調用loadRaw.pl

use strict; 
use warnings; 

use MongoDB; 
use MongoDB::Connection; 
use MongoDB::OID; 

print "hello\n"; 

當我嘗試運行該腳本,我收到了一堆錯誤:

$ perl ./loadRaw.pl 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 271, near "confess "cannot set fields after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 273, near "confess 'not a hash reference'" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 294, near "confess "cannot set sort after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 296, near "confess 'not a hash reference'" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 317, near "confess "cannot set limit after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 343, near "confess "Cannot set tailable state"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 366, near "confess "cannot set skip after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 390, near "confess "cannot set snapshot after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 408, near "confess "cannot set hint after querying"" 
    (Do you need to predeclare confess?) 
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 410, near "confess 'not a hash reference'" 
    (Do you need to predeclare confess?) 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 90, near "has started_iterating" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 271, near "confess "cannot set fields after querying"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 294, near "confess "cannot set sort after querying"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 317, near "confess "cannot set limit after querying"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 343, near "confess "Cannot set tailable state"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 366, near "confess "cannot set skip after querying"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 390, near "confess "cannot set snapshot after querying"" 
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 408, near "confess "cannot set hint after querying"" 
BEGIN not safe after errors--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 564. 
Compilation failed in require at /usr/local/lib/perl/5.10.1/MongoDB/Connection.pm line 26. 
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB/Connection.pm line 26. 
Compilation failed in require at /usr/local/lib/perl/5.10.1/MongoDB.pm line 30. 
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB.pm line 30. 
Compilation failed in require at ./loadRaw.pl line 7. 
BEGIN failed--compilation aborted at ./loadRaw.pl line 7. 

似乎MongoDB Perl模塊(特別是Cursor.pm文件)有一些語法錯誤。如果我將use Carp;行添加到Cursor.pm的頂部,就可以解決第一批問題(與confess關鍵字相關的問題)。但是,我認爲我不應該這樣做,而是我做了其他不正確的事情。此外,第二批錯誤(與has關鍵字有關的錯誤)不能通過包含Carp解決。

有沒有其他人經歷過這個?有任何想法嗎?

+0

對我來說編譯得很好。我在版本5.14.2中使用perlbrew。不知道是否會有所作爲。嘗試重新安裝它,看看你是否有任何錯誤。 – jmcneirney

+0

你安裝了什麼版本的Moose? ('perl -MMoose -le'print $ Moose :: VERSION''')您可能需要升級。 – friedo

+0

@jmcneirney:我正在使用5.10.1。我也嘗試了最新的perl 5.16.0,但這似乎沒有幫助。 – stepthom

回答

1

我從來沒有發現到底發生了什麼問題,但它對我的系統和我的Perl配置肯定是獨一無二的。既然別人能夠毫無問題執行所提供的代碼,我試着執行使用Perlbrew代碼(由friedo的建議):

$ perlbrew install perl-5.16.0 
(Output not shown) 
$ perlbrew switch perl-5.16.0 
(Output not shown) 
$ perlbrew install-cpanm 
(Output not shown) 
$ /home/sthomas/perl5/perlbrew/bin/cpanm MongoDB 
(Output not shown) 
$ perlbrew exec perl ./loadRaw.pl 
perl-5.16.0 
========== 
hello 

由於它工作正常使用Perlbrew安裝,問題不在於MongoDB的還是我的示例代碼;它一定是我的Perl環境的一些奇怪的怪癖。我想我會嘗試新安裝的Perl和我所需的所有模塊,看看是否可行。