0

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";
1
  • 1
    Why are you using an outdated book? Commented Mar 28, 2010 at 19:15

2 Answers 2

2

The first thing you have done wrong is to comment out use strict, the second is to use -w instead of use warnings.

With strict turned on, perl will report:

Bareword "XML::Parser" not allowed while "strict subs" in use at tmp:test.pl line 19.

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:

my $results = XML::Smart->new($esearch.$query,"XML::Parser");

… and it runs.

(Incidentally, the language is called "Perl", not "perl" or "PERL")

Sign up to request clarification or add additional context in comments.

1 Comment

I'm running this from OSX terminal. I don't see an array (or anything for that matter from the print "$all_Id\n"; command. Shouldn't this return 10 Ids? Follow the link: eutils.ncbi.nlm.nih.gov/entrez/eutils/…
-1

change:

my @Id = $results->{eSearchResult}{IdList}{Id}{'@'};

to:

my @Id = $results->{eSearchResult}{IdList}{Id}('@');

2 Comments

This should be edited into the question, not added as an answer.
you perl people are up tight. This was an obvious mistake I made, and it is the solution that solved the problem. Thus an answer. I'm going back to my ruby book now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.