[Buffalo-pm] Where is the extra newline coming from?
G Shankar
vieweremail at gmail.com
Mon Oct 30 13:47:55 PST 2006
Hello all,
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.
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.
Any help would be appreciated.
Thanks,
Ganesh
</code>
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
if ($#ARGV != 0) {
print "usage: getCitNum geneFileName \n";
exit;
}
my $geneFile = $ARGV[0];
my @gene=();
my $size;
# Creates the URL to search Pubmed
my $baseurl="http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?";
my $request;
my $response;
my $query;
open( FILE, "< $geneFile" ) or die "Can't open $geneFile : $!";
while( <FILE> ) {
next if /^(\s)*$/; # skip blank lines
##chomp; # remove trailing newline characters
##print "pushed ".$_." into array";
push @gene, $_; # push the data line onto the array
}
close FILE;
$size = scalar @gene;
print "Number of genes: $size.\n";
## iterate through the gene array
foreach my $gene (@gene){
##print "going through the array!","\t", $gene;
##$query=join(" ", $gene);
my $url=$baseurl . "db=Pubmed&retmax=1&usehistory=y&term=" . $gene;
$request=LWP::UserAgent->new();
$response=$request->get($url);
my $results= $response->content;
die unless $response->is_success;
$results=~/<Count>(\d+)<\/Count>/;
## $1 is the symbol for the matched content
my $NumAbstracts=$1;
print $gene,"\t",$NumAbstracts."\n";
}#end foreach gene array
</code>
</output>
$ perl o3.pl test_f
Number of genes: 8.
Actn1
5
Actn4
68
Adfp
74
Aldh2
656
"Siahbp1, simi"
0
1810057F21Rik
0
2310035N23Rik
0
2310040G17Rik 0
</output>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/buffalo-pm/attachments/20061030/6c9a8d2e/attachment.html
More information about the Buffalo-pm
mailing list