Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: CGI and Perl script one file, passing arguments

by Your Mother (Archbishop)
on Dec 09, 2014 at 23:23 UTC ( [id://1109829]=note: print w/replies, xml ) Need Help??


in reply to CGI and Perl script one file, passing arguments

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1109829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found