e_utilities.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/perl -w
  2. # ---------------------------------------------------------------------------
  3. # Define library for the 'get' function used in the next section.
  4. # $utils contains route for the utilities.
  5. # $db, $query, and $report may be supplied by the user when prompted;
  6. # if not answered, default values, will be assigned as shown below.
  7. use LWP::Simple;
  8. use utf8;
  9. my $utils = "http://www.ncbi.nlm.nih.gov/entrez/eutils";
  10. my $db = "Pubmed";
  11. my $query = $ARGV[0];
  12. my $report = $ARGV[1];
  13. # ---------------------------------------------------------------------------
  14. # $esearch contÁins the PATH & parameters for the ESearch call
  15. # $esearch_result containts the result of the ESearch call
  16. # the results are displayed Ánd parsed into variables
  17. # $Count, $QueryKey, and $WebEnv for later use and then displayed.
  18. my $esearch = "$utils/esearch.fcgi?" .
  19. "db=$db&retmax=1&usehistory=y&term=";
  20. my $esearch_result = get($esearch . $query);
  21. $esearch_result =~
  22. m|<Count>(\d+)</Count>.*<QueryKey>(\d+)</QueryKey>.*<WebEnv>(\S+)</WebEnv>|s;
  23. my $Count = $1;
  24. my $QueryKey = $2;
  25. my $WebEnv = $3;
  26. # ---------------------------------------------------------------------------
  27. # this area defines a loop which will display $retmax citation results from
  28. # Efetch each time the the Enter Key is pressed, after a prompt.
  29. my $retstart;
  30. my $retmax=3;
  31. for($retstart = 0; $retstart < $Count; $retstart += $retmax) {
  32. my $efetch = "$utils/efetch.fcgi?" .
  33. "rettype=$report&retmode=text&retstart=$retstart&retmax=$retmax&" .
  34. "db=$db&query_key=$QueryKey&WebEnv=$WebEnv";
  35. #print "\nEF_QUERY=$efetch\n";
  36. my $efetch_result = get($efetch);
  37. #open( $fh, '>', \$efetch_result);
  38. print $efetch_result;
  39. #print binmode($fh, ":utf8");
  40. }