
bobekdj
Novice
Dec 12, 2008, 8:08 PM
Post #1 of 16
(1067 views)
|
|
Passing a file from a form, processing, and then outputting as html
|
Can't Post
|
|
Hello everyone, I am sorry if I am asking something that can be pieced together from the forums, but i have searched google and forums for a few hours now, and cant get this code to work. *all of these codes work fine by them selves, but assembling them seems to be a problem. What i am trying to do is make a simple form, have an upload box for a file which contains data. This file is then processed via perl script, and then the results need to print out in the browser. I have managed to create a basic form and know it is passing things to the perl script, but for some reason after that, i can print statements BEFORE ANY of the "processing", but after, none of the printing shows in the browser. Also, all of the lines which print in the terminal, do not print in the html page. I am really lost and any help would be appreciated, below is the code for the 3 files. Thank you for any assistance you can provide
concepts.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Form Example</title> </head> <body> <!-- Insert your content here --> <form action="cgi-bin/concepts2.pl" method="post"> <p>File:<input type="FILE" name="file"> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
concepts2.pl #!/usr/bin/perl use strict; use CGI; my $cgi=new CGI; print $cgi->header(); print $cgi->start_html(-title=>'Form Results', -author=>'BoChak'); #my $file=$cgi->param('file'); my $file="/root/Desktop/test.fasta"; print "<br> $file <br>"; ################ Process File ######################### #my $file=<>; my $seqname=''; my $sequence=''; my %seqhash=(); open (FILE,"<$file") or die "Can't open $file\n"; while (my $line=<FILE>){ chomp($line); if ($line=~m/^>/){ my @temp=split(' ',$line); $seqname=substr($temp[0],1); } elsif ($line=~m/^\s$/||$line=~m/^$/){ $seqhash{$seqname}=$sequence; } else { $sequence=$sequence.$line; } } close (FILE); ######################################################## foreach my $key (keys %seqhash){ my $risk=docParser->new($key, $seqhash{$key} ); $risk->CAG_count(); } print $cgi->end_html."\n";
docParser.pm package docParser; use strict; sub new { my $class = shift; my $self = bless {}, $class; my $seqname=shift; my $sequence=shift; $self->{_seqname}=$seqname; $self->{_sequence}=$sequence; return $self; } sub CAG_count { my ($self)=shift; my $seqname=$self->{_seqname}; my $sequence=$self->{_sequence}; my $count_of_CAG=0; my @seq=split(//,$sequence); my $aa=''; my @position; my $len; my $amino_acid_number; for (my $index=0; $index<$#seq-2; $index+=3) { if ($sequence=~m/((CAG){6,})/g){ $count_of_CAG++; @position=index($sequence,$1); $len=length($1)/3; $amino_acid_number=shift(@position); } } print "For the sequence ".$seqname." we found a CAG string "; print "with $len\n repeats "; print "at amino acid number ".$amino_acid_number."\n\n"; if ($len<35) { print "Risk Evaluation: Normal"."\n\n"; } elsif ($len>36||$len<48) { print "Risk Evaluation: Warning"."\n\n"; } elsif ($len>48) { print "Risk Evaluation: Dangerous"."\n\n"; } } 1;
|