Perl: Populate array from XML output (PubMed UIDs via Eutils) -


i'm trying build array of id's xml output generated pubmed's eutils.

here code on github. , below specific subroutine.

what's best way go this?

getuid($query);  sub getuid {    # first, build eutils query   $utils = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils'; # base url searches   $db = 'pubmed'; # default pubmed database; may changed.   $retmax = 10; # 10 results eutils    $esearch = $utils . '/esearch.fcgi?db=' . $db . '&retmax=' . $retmax . '&term=';    $esearch_result = get( $esearch . $query ); # downloads xml    # second, extract uids   $esearch_result =~ m(<id>*</id>);          print $esearch_result; # should return list of id's (numbers), doesn't.  } 

here pubmed xml result looks like:

<?xml version="1.0" ?> <!doctype esearchresult public "-//nlm//dtd esearchresult, 11 may 2002//en" "http://www.ncbi.nlm.nih.gov/entrez/query/dtd/esearch_020511.dtd"> <esearchresult><count>2768671</count><retmax>10</retmax><retstart>0</retstart><idlist> <id>23682407</id> <id>23682406</id> <id>23682388</id> <id>23682359</id> <id>23682336</id> <id>23682331</id> <id>23682325</id> <id>23682320</id> <id>23682315</id> <id>23682311</id> </idlist><translationset><translation>     <from>cancer</from>     <to>"neoplasms"[mesh terms] or "neoplasms"[all fields] or "cancer"[all fields]</to>    </translation></translationset><translationstack>   <termset>    <term>"neoplasms"[mesh terms]</term>    <field>mesh terms</field>    <count>2430901</count>    <explode>y</explode>   </termset>   <termset>    <term>"neoplasms"[all fields]</term>    <field>all fields</field>    <count>1920766</count>    <explode>y</explode>   </termset>   <op>or</op>   <termset>    <term>"cancer"[all fields]</term>    <field>all fields</field>    <count>1192293</count>    <explode>y</explode>   </termset>   <op>or</op>   <op>group</op>  </translationstack><querytranslation>"neoplasms"[mesh terms] or "neoplasms"[all fields] or "cancer"[all fields]</querytranslation></esearchresult> 

if want match return string, have add capturing parentheses. if there several matches, use g option. store result in array:

 @matches = $esearch_result =~ m(<id>(.*)</id>)g;  print "$_\n" @matches; 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -