我正在继续使用过时的 生物信息学书籍,我正在尝试使用XML::智能模块。
我怀疑该模块的方法在 6 年的时间里已经发生了变化,而且我对 Perl 没有经验,无法从 cpan 源。注释掉的代码证明了 ncbi.gov 查询功能,我在使用“新”方法时遇到了麻烦 - 它没有解析 XML。我做错了什么?谢谢!
更新 具体来说,我在解析和显示 Id 数组时遇到了麻烦: my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
我在 OSX 终端上运行此脚本,但运行此脚本时没有看到任何 Id。我看到了正确的伯爵。谢谢!
#!/usr/local/bin/perl
# use lib "/Users/fogonthedowns/myperllib";
# use LWP::Simple;
use XML::Smart;
use strict;
#Set base URL for all eutils
my $utils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils";
my $db = "Pubmed";
my $query ="Cancer+Prostate";
my $retmax = 10;
my $esearch = "$utils/esearch.fcgi?" .
"db=$db&retmax=$retmax&term=";
# my $esearch_result = get($esearch.$query);
# print "ESEARCH RESULT: $esearch_result\n";
# print "Using Query: \n$esearch$query\n";
# print "hello world\n";
my $results = XML::Smart->new($esearch.$query,"XML::Parser");
my $count = $results->{eSearchResult}{Count};
my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
my $all_Id = join("\n", @Id);
print "Count = $count\n";
print "$all_Id\n";
I'm continuing to work out of an outdated bioinformatics book and I'm attempting to use the XML::Smart Module.
I suspect the module's methods have changed over the course of 6 years and I'm inexperienced with perl to troubleshoot from cpan source. The commented out code proves the ncbi.gov query functions, I'm having trouble with the 'new' method - it's not parsing the XML. What am I doing wrong? Thanks!
Update Specifically I'm running into trouble with parsing and displaying the Id array: my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
I'm running this on OSX terminal and I don't see any Ids when I run this script. I am seeing the proper Count. Thanks!
#!/usr/local/bin/perl
# use lib "/Users/fogonthedowns/myperllib";
# use LWP::Simple;
use XML::Smart;
use strict;
#Set base URL for all eutils
my $utils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils";
my $db = "Pubmed";
my $query ="Cancer+Prostate";
my $retmax = 10;
my $esearch = "$utils/esearch.fcgi?" .
"db=$db&retmax=$retmax&term=";
# my $esearch_result = get($esearch.$query);
# print "ESEARCH RESULT: $esearch_result\n";
# print "Using Query: \n$esearch$query\n";
# print "hello world\n";
my $results = XML::Smart->new($esearch.$query,"XML::Parser");
my $count = $results->{eSearchResult}{Count};
my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
my $all_Id = join("\n", @Id);
print "Count = $count\n";
print "$all_Id\n";
发布评论
评论(2)
你做错的第一件事是注释掉
use strict
,第二件事是使用-w
而不是use warnings
。当严格打开时,perl 将报告:
这让我们可以跟踪问题发生的位置。
文档中的示例表示第二个参数(要使用的解析器)应该被引用了,而你还没有引用它。
所以我们改为:
……然后它就运行了。
(顺便说一下,该语言被称为“Perl”,而不是“perl”或“PERL”)
The first thing you have done wrong is to comment out
use strict
, the second is to use-w
instead ofuse warnings
.With strict turned on, perl will report:
This lets us trace where the problem is occurring.
The examples in the documentation say that the second argument (the parser to use) should be quoted, and you haven't quoted it.
So we change to:
… and it runs.
(Incidentally, the language is called "Perl", not "perl" or "PERL")
将
:
my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
更改为:
my @Id = $results->{eSearchResult} {IdList}{Id}('@');
change:
my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};
to:
my @Id = $results->{eSearchResult}{IdList}{Id}('@');