Hello all,<br><br>I've gotten back to hacking with perl again. I'm confused by the output of a little program I'm writing. It builds a query in the form of a url to PubMed and parses the returning xml for the 'count' field. Fine so far. After that, I'm trying to print out results in a particular format; namely, query term(gene), tab, count, newline.
<br><br>But the output is coming out query term(gene), newline,tab, count, newline. O Great Mongers! Where is the extra newline coming from? I've tried to chop and chomp both variables ($gene and $NumAbstracts) but to no avail.
<br><br>Any help would be appreciated.<br>Thanks,<br>Ganesh<br><br></code><br><br>#!/usr/bin/perl<br>use strict;<br>use warnings;<br>use LWP;<br><br><br>if ($#ARGV != 0) {<br> print "usage: getCitNum geneFileName \n";
<br> exit;<br>}<br><br>my $geneFile = $ARGV[0];<br>my @gene=();<br>my $size;<br># Creates the URL to search Pubmed<br>my $baseurl="<a href="http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?">http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?
</a>";<br>my $request;<br>my $response;<br>my $query;<br><br>open( FILE, "< $geneFile" ) or die "Can't open $geneFile : $!";<br><br> while( <FILE> ) {<br> next if /^(\s)*$/; # skip blank lines
<br> ##chomp; # remove trailing newline characters<br> ##print "pushed ".$_." into array";<br> push @gene, $_; # push the data line onto the array<br> }<br><br> close FILE;
<br> <br><br>$size = scalar @gene;<br>print "Number of genes: $size.\n";<br><br><br>## iterate through the gene array<br><br>foreach my $gene (@gene){<br><br>##print "going through the array!","\t", $gene;
<br><br>##$query=join(" ", $gene);<br>my $url=$baseurl . "db=Pubmed&retmax=1&usehistory=y&term=" . $gene;<br>$request=LWP::UserAgent->new();<br>$response=$request->get($url);<br>my $results= $response->content;
<br>die unless $response->is_success;<br>$results=~/<Count>(\d+)<\/Count>/;<br>## $1 is the symbol for the matched content<br> my $NumAbstracts=$1;<br><br>print $gene,"\t",$NumAbstracts."\n";
<br><br>}#end foreach gene array<br><br></code><br><br></output><br><br>$ perl o3.pl test_f<br>Number of genes: 8.<br>Actn1<br> 5<br>Actn4<br> 68<br>Adfp<br> 74<br>Aldh2<br> 656<br>
"Siahbp1, simi"<br> 0<br>1810057F21Rik<br> 0<br>2310035N23Rik<br> 0<br>2310040G17Rik 0<br><br></output><br>