首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Perl连接到MongoDB时出现编译错误

从Perl连接到MongoDB时出现编译错误
EN

Stack Overflow用户
提问于 2012-10-29 23:41:12
回答 1查看 1.1K关注 0票数 4

我正在尝试运行简单的"MongoDB:Tutorial“教程:

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

我的目标是从Perl脚本连接到MongoDB数据库。我使用cpanm安装了MongoDB:

代码语言:javascript
复制
$ sudo cpanm MongoDB
MongoDB is up to date. (0.501.1)

我创建了一个名为loadRaw.pl的简单Perl脚本

代码语言:javascript
复制
use strict;
use warnings;

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

print "hello\n";

当我尝试运行脚本时,我得到了一堆错误:

代码语言:javascript
复制
$ 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来解决。

还有没有人经历过这种情况?有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-30 07:50:38

我从来没有找出到底是哪里出了问题,但这肯定是我的系统和Perl配置所独有的。由于其他人可以毫无问题地执行提供的代码,因此我尝试使用Perlbrew执行代码(根据friedo的建议):

代码语言:javascript
复制
$ 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和所有需要的模块,看看是否能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13124876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档