use vars qw($DEBUG);
my %options = (debug => 0,
- help => 0,
- man => 0,
- color => 1,
- org_mode => 0,
- );
+ help => 0,
+ man => 0,
+ color => 1,
+ org_mode => 0,
+ abstract => 1,
+ );
GetOptions(\%options,
'color|c!',
'org_mode|org-mode',
'pmid_only|pmid-only',
+ 'abstract|a!',
'debug|d+','help|h|?','man|m');
pod2usage() if $options{help};
-term => join(' ',@ARGV),
-retmax => 1000,
)->run();
+if ($result eq '0') {
+ print "No results\n";
+ exit;
+}
my @ids = $result->ids;
+if (@ids > 0 and ref($ids[0])) {
+ @ids = @{$ids[0]};
+}
if ($options{org_mode}) {
print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
print " + ";
)->run(-raw_xml => 1);
use XML::LibXML;
my $xml = XML::LibXML->load_xml(string => $raw_xml);
-for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
- # print $article->toString;
- my ($pmid) = $article->findnodes('./PMID');
- my ($title) = $article->findnodes('./Article/ArticleTitle');
- my ($abstract) = $article->findnodes('./Article/Abstract');
+print STDERR $xml->toString if $DEBUG;
+for my $article ($xml->findnodes(q{//*[local-name()='MedlineCitation']})) {
+ print STDERR $article->toString if $DEBUG;
+ my ($pmid) = $article->findnodes(q{./*[local-name()='PMID']});
+ my ($title) = $article->findnodes(q{./*[local-name()='Article']}.
+ q{/*[local-name()='ArticleTitle']});
+ my ($abstract) = $article->findnodes(q{./*[local-name()='Article']}.
+ q{/*[local-name()='Abstract']});
if ($options{org_mode}) {
print "** PMID: ";
}
print BOLD CYAN if $options{color};
print encode_utf8($title->textContent())."\n";
print RESET if $options{color};
- print BOLD MAGENTA if $options{color};
- if (defined $abstract) {
+ if (defined $abstract and $options{abstract}) {
+ print BOLD MAGENTA if $options{color};
if ($options{org_mode}) {
print "*** Abstract\n";
}