連接到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
解決。
有沒有其他人經歷過這個?有任何想法嗎?
對我來說編譯得很好。我在版本5.14.2中使用perlbrew。不知道是否會有所作爲。嘗試重新安裝它,看看你是否有任何錯誤。 – jmcneirney
你安裝了什麼版本的Moose? ('perl -MMoose -le'print $ Moose :: VERSION''')您可能需要升級。 – friedo
@jmcneirney:我正在使用5.10.1。我也嘗試了最新的perl 5.16.0,但這似乎沒有幫助。 – stepthom