#!/usr/local/bin/perl -w #use strict; #use warnings; use DBI; use Net::MySQL; use HTTP::Request::Common; use LWP::UserAgent; use CGI qw(header -no_debug); use XML::Twig; #==============================database connection================================================ #=============================end database connection================================================== $mysql->query(qq{SELECT accession_code FROM protein}); my $record_set = $mysql->create_record_iterator; while (my $record = $record_set->each) { print "Accession ID: $record->[0] \n"; #For retrieving data from a url post in perl, we will use the LWP module "get" function use LWP::Simple; #supports the "get" function $baseurl="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/"; $eutil="esearch.fcgi?"; $parameters="db=protein&term=$record->[0]&retmode=xml"; $url=$baseurl.$eutil.$parameters; $raw=get($url); open(FILE, ">$record->[0]"); print FILE $raw; close FILE; $xml_file = $record->[0]; my $twig= XML::Twig->new( TwigHandlers => { "/eSearchResult/IdList/Id" => \&id_Tag } ); #actually parse the file $twig->parsefile($xml_file) or die "cannot parse [$xml_file]: $!"; ########################################### sub id_Tag { ########################################### my($t, $idTag)= @_; print $idTag->text(), "\n"; # Release memory of processed tree up to here $t->purge(); } }