473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HTML::Form

76
can anyone please give me an example of how to use
HTML::Form module
and its method
@values = $form->param( $name )

thanks alot.
Mar 14 '07 #1
15 2745
miller
1,089 Expert 1GB
can anyone please give me an example of how to use
HTML::Form module
and its method
@values = $form->param( $name )

thanks alot.
Hi idorjee,

Instead of fixating on a particular solution, I would suggest that you state what your real problem is. Maybe there is a module that would better serve what you're trying to do.

Nevertheless, if you're wanting to figure out this module, always start with the cpan documentation:

cpan HTML::Form

As a secondary means of understanding it's usage, I'll often take a look at the test scripts that are provided with the package. This is definitely something for the more advanced, but it gives you more direct insight into how the authors expected the module to be used.

http://search.cpan.org/src/GAAS/libw...-5.805/t/html/

- Miller
Mar 14 '07 #2
idorjee
76
hi miller,
i'm trying to get the input from the html textarea into a file or a variable, so that i could than execute with a perl script that i've written.
I thought using HTML::Form module would do the thing, but unfortunately i haven't used it before and don't know how it works.

--------part of myfile.html----------
<b>Query sequence in fasta format:</b><br>
<textarea name="sequence" cols="61" rows="10"></textarea>
<br>

---------part of myfile.cgi------------
$seq=$query->param('sequence');
system("perl ncbi2tcblast.pl \$seq");

the above doesn't work for some reason, which i think is because the sequence that i paste in the form (textarea) doesn't get it in $seq variable in the same format (ie, everything seems to be in one long line without any new line characters). so, i thought i should try HTML::Form. And also, i am trying to get the result of the 'system("perl ncbi2tcblast.pl \$seq");' on the browser.

thanks
:)
Mar 14 '07 #3
miller
1,089 Expert 1GB
---------part of myfile.cgi------------
$seq=$query->param('sequence');
system("perl ncbi2tcblast.pl \$seq");
Idorjee,

I believe your problem is not in the parsing of the html textarea "sequence", but in how your calling ncbi2tcblast.pl.

To verify that you textarea is being parsed correctly, set up a debugging check to a text file.

Expand|Select|Wrap|Line Numbers
  1. $seq = $query->param('sequence');
  2. open(VERIFY,"sequence.txt") or die "Can't open sequence.txt: $!";
  3. print VERIFY "'$seq'";
  4. close VERIFY;
  5.  
Obviously, you should probably specify an explicit path for sequence.txt if you want to be sure of where it lands. But look at its contents to verify that your $seq variable is being set correctly.

I'm assuming that since this is textarea value, that it's going to be multiple lines. This will lead to problems in the system call. A system call essentially functions like any shell command does. If you can't have multiple lines in a shell call, you won't be able to get it to work froma system either.

I suggest that you use the following method instead if your goal is to simply call the script ncbi2tcblast.pl will the first argument of $seq.

Expand|Select|Wrap|Line Numbers
  1. local @ARGV = ($seq);
  2. do 'ncbi2tcplast.pl';
  3.  
- Miller
Mar 15 '07 #4
idorjee
76
Hi Miller,
I really appreciate your trying to help me out with this, but nothing seem to be working. I tried what you told me to do, and I can't even get the 'sequence.txt' file to verify. Following is the entire script. Could you plz tell me where am I going wrong. I think it's something simple, but I can't figure that out.
Thanks alot.

------ myscript.cgi ---------

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use CGI;
  3.  
  4. use strict;
  5.  
  6. my $infile = "tcresult.bls";
  7. open(INFILE, "$infile") or die "Can't open $infile: $!";
  8.  
  9. my $query = new CGI;
  10.  
  11. print STDOUT $query->header();
  12. print STDOUT $query->start_html(-title=>"Response from blast", -BGCOLOR=>"#FFFFFF");
  13.  
  14. print STDOUT "\n<h1><center><font face=times new roman>Results from the BLAST</font></center></h1>\n";
  15.  
  16. my $seq = $query->param('sequence');
  17. open(VERIFY,"sequence.txt") or die "Can't open sequence.txt: $!";
  18. print VERIFY "'$seq'";
  19. close VERIFY;
  20.  
  21. print STDOUT "<pre>";
  22. local @ARGV = ($seq);
  23. do 'ncbi2tcblast.pl';
  24. while(<INFILE>){
  25.     print STDOUT $_;
  26. }
  27. print STDOUT "</pre>";
  28.  
  29. unlink "/path/apache/htdocs";
  30. print STDOUT $query->end_html;
  31. print "\n";
  32.  
Mar 15 '07 #5
miller
1,089 Expert 1GB
Hi idorjee,

Boy, the more code of yours I see, the more tired I become. Ok, this is my advice:

Cut out everything dealing with running an external script and focus on getting CGI to work. This is a really simple requirement, so you want to make sure that this is working on it's own before adding any additional features.

I notice two things currently:

Where is your definition of the sequence textarea? And why are you trying to unlink your htdocs directory at the bottom of the script?

Anyway, focus on CGI and once that is working you can add on more features.

- Miller
Mar 15 '07 #6
KevinADC
4,059 Expert 2GB
You're script is quite confusing. Can you explain step-by-step what you are trying to do.

1. get textarea data (sequence)
2. ?
3. ?
etc
etc


this looks dangerous:

Expand|Select|Wrap|Line Numbers
  1. unlink "/path/apache/htdocs";
Never delete directories using the unlink function, which is for files. That could hose up your computer quite nicely. Use rmdir() to delete a directory, but why do you want to delete the htdocs directory anyway?
Mar 15 '07 #7
idorjee
76
You're script is quite confusing. Can you explain step-by-step what you are trying to do.
hi Kevin,
following are the things that i am trying to do:
1. get textarea data (sequence) from my html form
2. run the 'ncbi2tcblast.pl' script with sequence from the textarea as the arg. and
3. show the output (in html form) on the browser
:(
thanks alot
Mar 15 '07 #8
idorjee
76
Hi idorjee,

Boy, the more code of yours I see, the more tired I become. Ok, this is my advice:
sorry about that, Miller. i'll try it from the scratch.
thanks
Mar 15 '07 #9
idorjee
76
hey kevin,

there's one more thing that i would like you to know. following is the part of the 'ncbi2tcblast.pl' script that i mentioned earlier. and as you can see that it takes an arg. file (@ARGV[0]) which should be the same (sequence) input from the html textarea, which i think is not getting here (in $fasta_file). all i could see on the browser is: "Blast in progress..." (until the line: print "Blast in progress...\n"; of the script).

thanks

--------- ncbi2tcblast.pl -------------

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use Bio::Perl;
  5. use Bio::SearchIO;
  6. use Bio::DB::GenPept;
  7.  
  8. my @s1array;
  9. my $fasta_file=@ARGV[0];
  10.  
  11. print "Blast in progress...\n";
  12.  
  13. system ("blastall -p blastp -d ../database/nrpart -i $fasta_file -o repo.bls");
  14.  
  15. my $in = new Bio::SearchIO(-format => 'blast', -file => 'repo.bls');
  16. while( my $result = $in->next_result ) {
  17.     while( my $hit = $result->next_hit ) {
  18.         while( my $hsp = $hit->next_hsp ) {
  19.             if ( $hsp->evalue <= 0.001 ) {
  20.                 print "Hit=", $hit->name, "\tDescription=", $hit->description, "\tAccession=", $hit->accession, "\tEvalue=", $hsp->evalue, "\tPercent_id=", $hsp->percent_identity, "\$
  21.                 push(@s1array, $hit->accession);
  22.             }
  23.         }
  24.     }
  25. }
  26.  
Mar 15 '07 #10
KevinADC
4,059 Expert 2GB
I think you're complicating things by having two scripts. Both of the scripts are very short and should be combined into one script unless there is some good reason not to do that I am not aware of.
Mar 16 '07 #11
miller
1,089 Expert 1GB
sorry about that, Miller. i'll try it from the scratch.
thanks
Sorry if my comment appeared snide, but there is no reason to apologize.

I was simply wanting to point out that it is very important to ensure that your different technological layers are working individually before trying to integrate them.

No matter how much experience forum experts have, the person who is in the best position to fix a bug will always be the actually coder. That is why it's important that you and everyone learn good code design and debugging practices, as it will help you the most in the long run.

Anyway, I'm going to be extremely busy the rest of this weekend, so I won't be able to help anyone. Good luck, and catch you next week if you're still working in this design problem.

- Miller
Mar 16 '07 #12
idorjee
76
Hi Kevin,
So, here is what I did to my script. I combined them into one just like what you suggested, and, you're right, cos it makes no sense having two small scripts. But I still have a smally problem with it. The following script prints out the '$fasta_file' on the browser, but it can't seem to open the same for the 'blast' when it comes to line:
my $seq_in=Bio::SeqIO->new('-file' => '$fasta_file', '-format' => 'fasta');

Thanks alot.

#### my script ########
#!/usr/bin/perl -w

use strict;
use Bio::Perl;
use Bio::SearchIO;
use Bio::DB::GenPept;
use Bio::SearchIO::Writer::HTMLResultWriter;
use Bio::SeqIO;
use Bio::Tools::Run::StandAloneBlast;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);

#generate a new CGI object from the input to the CGI script
my $query=new CGI;

my @s1array;
my $fasta_file;

print STDOUT $query->header();
print STDOUT $query->start_html(-title=>"Response from blast", -BGCOLOR=>"#FFFFFF");
print STDOUT "\n<h1><center><font face=times new roman>Results from the BLAST</font></center></h1>\n";

#the input from the html form - textarea
my $fasta_file=$query->param('sequence');
print STDOUT "<br>The contents of the uploaded file:\n<br></b>\n";

#prints out the sequence from the textarea on the browser
print STDOUT $fasta_file;

#performs blast of the sequence ($fasta_file) against the database (nr) and store the output in 'result/repo.bls'
my $seq_in=Bio::SeqIO->new('-file' => '$fasta_file', '-format' => 'fasta');
my $queryin=$seq_in->next_seq();
my @params = ('program' => 'blastp','database' => 'database/nr','outfile' => 'result/repo.bls', '_READMETHOD' => 'Blast');
my $factory=Bio::Tools::Run::StandAloneBlast->new(@params);
my $blast_report=$factory->blastall($queryin);





I think you're complicating things by having two scripts. Both of the scripts are very short and should be combined into one script unless there is some good reason not to do that I am not aware of.
Mar 27 '07 #13
miller
1,089 Expert 1GB
Dude,

You've already posted this problem in a new thread. And answers have already been given.

Start keeping track of your threads. This is like the third time this has been an issue with you.

http://www.thescripts.com/forum/thread623394.html

- Miller
Mar 27 '07 #14
KevinADC
4,059 Expert 2GB
data sent from a textarea form widget can contain carraige returns and newlines or some combination of both, they need to be removed if that data is being used as a filename:

Expand|Select|Wrap|Line Numbers
  1. $string =~ s/[\r\n]//g;

where $string is the data from the textarea form widget.
Mar 27 '07 #15
idorjee
76
Sorry Miller, I just realized that. Won't happen again.
Cheers. ^ ^*


Dude,

You've already posted this problem in a new thread. And answers have already been given.

Start keeping track of your threads. This is like the third time this has been an issue with you.

http://www.thescripts.com/forum/thread623394.html

- Miller
Mar 27 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sammmista | last post by:
hello experts, Plz dont treat this as another newbie query , i did my homework but still getting nowhere :( :( :( Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to post data...
7
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
1
by: Glen | last post by:
Hi, Do you know if it's possible to send an HTML E-Mail with an HTML Form (<form></form>) embedded in it?? And if so, will Outlook (a) render the form properly and (b) allow you to submit the...
2
by: Mark | last post by:
Hi all, I have a WYSIWYG editor which allows people to insert a form into a page. This information is stored in a database and at run-time is displayed inside a content placeholder (I'm using...
1
by: John Wolff | last post by:
I’m trying to upload a file to a Web Service. I have to submit the file using a standard HTML form with the <input type=“file” /tag. Ultimately, we are submitting the file from a Flash 8...
0
by: bp_jobemail | last post by:
I'm trying to use PHP to wrap the output of an HTML form before it goes into a precompiled C cgi script. Essentially, the company that I work for uses a purchased precompiled c program for their...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
1
by: Lelu | last post by:
Hi, My HTML form is generating some blank email responses; does anyone see anything wrong with the scripts?: function isFormVarExcluded(thisForm, strToCheck) { var strExcludeVars =...
2
by: Jibran | last post by:
I need some help with extra spaces in HTML form. There is a big white space appearing at the center of the HTML form that I am designing even though there is no <br> tags been used: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.