簡體   English   中英

從Perl連接到MongoDB時的編譯錯誤

[英]Compilation errors when connecting to MongoDB from Perl

我正在嘗試運行簡單的“MongoDB:Tutorial”教程:

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)

我創建了一個名為loadRaw.pl的簡單Perl腳本:

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;第一批問題(與confess關鍵字相關的問題)就解決了use Carp; Cursor.pm的頂部。 但是,我認為我不應該這樣做,而是我正在做其他錯誤的事情。 此外,第二批錯誤(與has關鍵字相關的錯誤)不能通過包含Carp來解決。

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

我從來沒有發現到底出了什么問題,但它確實是我的系統和我的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和我所需的所有模塊,看看是否有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM