Command line version. Adapt, amend, etc as necessary. What NetWallah said. Use CGI if you’re keeping it in the CGI realm (or another modern framework). Required reading: XML::LibXML, XML::LibXML::Node, URI, and as a pre-emptive measure if the following are daunting: Yes, even you can use CPAN, local::lib, cpanm. Getopt::Long if you want deep(er) argument handling.
#!/usr/bin/env perl # Script/file named pm-1109805 use strictures; use XML::LibXML; use URI; my $term = shift || die "Give a term to search the nuccore DB!\n"; my %args = ( db => "nuccore", retmax => 1, usehistory => "y", term => $term ); my $uri = URI->new("http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch. +fcgi"); $uri->query_form(%args); # If you don't expect errors and don't need cookies etc, use XML::LibX +ML, # if you do, use LWP::UserAgent or WWW::Mechanize or something. my $dom = XML::LibXML->load_xml( location => $uri->as_string ); # Expecting exactly ( one ), findnodes returns a list. my ( $result ) = $dom->findnodes("/eSearchResult"); my $error = $result->findvalue("/ERROR"); die "Error:", "$error", $/ if $error; my $count = $result->findvalue("Count"); my $showing = $result->findvalue("RetMax"); printf "Found %d result%s. Showing %d (RetMax).\n", $count, $count == 1 ? "" : "s", $showing; for my $id ( $result->findnodes("IdList/Id") ) { print "Id: ", $id->textContent, $/; } # print $dom->serialize(1); # To see the raw XML.
moo@cow[54]~>pm-1109805 NM_000040 Found 1 result. Showing 1 (RetMax). Id: 4557322 moo@cow[55]~>pm-1109805 asdf Found 15 results. Showing 1 (RetMax). Id: 57648377
In reply to Re: CGI and Perl script one file, passing arguments
by Your Mother
in thread CGI and Perl script one file, passing arguments
by newtoperlprog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |