Dear Monks

I have a script which fetches the summary file from the NCBI website using command line argument(accession number).

Example: ./efetch.pl NM_000040

Now I am trying to fetch the same file using a HTML webpage which takes the form request via a cgi script.

My question: Is it possible to combine the cgi and my perl script in one file and pass the HTML form argument from the cgi portion of the code to the perl script in single run.

I have tried to do some scripting but it seems that the argument from the cgi is not getting passed to the perl script.

Any help will be greatly appreciated

CGI and Perl Script in one single file #!/usr/bin/perl -wT use strict; use warnings; use LWP::Simple; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); ################### Environmental Variables ################### my ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text + $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } #print "$buffer\n"; # Split information into name/value pairs + @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; # $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } my $access = $FORM{accession}; if ($access =~ m{\A(\w+\d+)\z}) { $access = $1; } print "Content-type:text/html\r\n\r\n"; print "<html>"; print "<head>"; print "<title> CGI Program</title>"; print "</head>"; print "<body>"; if ($access eq "") { print "<h2> Please check the accession number</h2>"; exit; } print "<h2>$access</h2>"; print "</body>"; print "</html>"; print <<HEADING <html> <head> <title> Output result of the program </title> </head> <body> <h1> Summary result </h1> <table border=1> <tr> <th>S.No.</th> <th>Fragment</th> <th>Position</th> <th>Region</th> <th>GC%</th> </tr> HEADING ; ######################## INPUT PARAMETERS ##################### my $utils = "http://www.ncbi.nlm.nih.gov/entrez/eutils"; my $db = "nuccore"; my $query = $access; #"$ARGV[0]" or die "Please provide input for the + accession number. $!"; ############### END OF INPUT PARAMETERS ###################### ############### FILE DOWNLOAD FROM NCBI ###################### my $report = "gb"; # downloads the summary text file open (IN,">", $query.".summary"); my $esearch = "$utils/esearch.fcgi?" . "db=$db&retmax=1&usehistory=y&t +erm="; my $esearch_result = get($esearch . $query); $esearch_result =~ m|<Count>(\d+)</Count>.*<QueryKey>(\d+)</QueryKey>. +*<WebEnv>(\S+)</WebEnv>|s; my $Count = $1; my $QueryKey = $2; my $WebEnv = $3; my $retstart; my $retmax=3; for($retstart = 0; $retstart < $Count; $retstart += $retmax) { my $efetch = "$utils/efetch.fcgi?" . "rettype=$report&retmode=text&retstart=$retstart&retmax=$retmax&" +. "db=$db&query_key=$QueryKey&WebEnv=$WebEnv"; my $efetch_result = get($efetch); print IN $efetch_result, "\n"; } close (IN);

Print command in the perl script prints the "$access" but it fails to pass the value of $access to $query.

HTML form: <form action="/cgi-bin/efetch.cgi" method="post" id="myform"> <div> NCBI accession number:<label for="accession"> <input type="tex +t" name="accession"></label><br> <input type="submit" value="Submit" form="myform"> </div> </form>

In reply to CGI and Perl script one file, passing arguments by newtoperlprog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.