MonkPaul has asked for the wisdom of the Perl Monks concerning the following question:
Further to my post eariler today on files and server interaction... i have a new problem, i cannot open files for reading or writing.
I know the code worked in the past from use with command line, but i have since tried to adapt it for use with a web page upload.
I cant see why it would work.
some variables declared before the method calls and the correct syntax + for a CGI script. ###################################################################### +######### sub get_Input() { $html = new CGI; # create a new instance of CGI to upload +file $blastFile = $html->param('blast_Upload'); # upload file $refFile = $html->param('ref_Upload'); # upload file $blastSeq = param("blast_Seq"); chomp($refFile); @dir = split(/\\/, $refFile); pop(@dir); $pathName = join('\\', @dir); print("<BR>$pathName is the location files will be saved to<BR>"); print("<BR>$blastFile<BR>"); print("<BR>$refFile<BR>"); } ###################################################################### +######### sub get_Results() { #my $referenceFile; #my $blastFile; #if using this WITHOUT an reference file as input, cmdline must be as +follows # --blastresult result.txt --reffile file.txt (even if it's an empty f +ile) #GetOptions( "blastresult=s" => \$blastFile, "reffile=s" => \$refFile) +; my $ref_File = "<" . $refFile; my $blast_File = "<" . $blastFile; print("<BR>$blast_File<BR>"); print("<BR>$ref_File<BR>"); ## open file handles.############## PROBLEM HERE ########## open( BLAST_FILE, $blast_File ) || die "$!"; open( REF_FILE, $ref_File ) || die "$!"; print("Blast File Opened<BR>"); print("Reference File Opened<BR>"); ## output files - open them my $newRefFile = "$pathName\\newRefFile.txt"; my $newBlastFile = "$pathName\\newBlastFile.txt"; open( NEW_ACC, ">$newRefFile" ) || die "$!"; open( NEW_ALIGN, ">$newBlastFile") || die "$!"; print("New files created<BR>"); ## put list of reference accessions into a structure so we can parse i +t... my $refList = {}; # reference to empty hash while (<REF_FILE>) { chomp; # removes newline charac +ter $refList->{$_} = ""; # $_ is whatever line is currently open, t +hus creating a hash with key = accession, value = " "(.: defined) } #PARSE BLAST RESULT HERE.... #read results file one line at a time my @resultLine = <BLAST_FILE>; my $alignment = {}; # reference to an empty hash my @subjects = []; # reference to empty array my $current_subject = "front_matter"; $alignment->{$current_subject} = ""; #so I produce a hash with key = >gi line of report and value = all lin +es after until next >gi for (my $i = 0 ; $i<scalar @resultLine; $i++) { if ($resultLine[$i] =~ /^>/) { $current_subject = $resultLine[ $i ]; chomp ($current_subject); push (@subjects, $current_subject); $alignment->{$current_subject} = ""; #$alignment->{$current +_subject} means give value of $alignment when $current_subject is the + key } $alignment->{$current_subject} = $alignment->{$current_subject} . +$resultLine[ $i ]; } my @elements; foreach my $z (@subjects) { chomp $z; print "$z\n"; @elements = split('\|', $z); if ( ! defined $elements[ 3 ] ) { print "<BR>Parsing Error<BR>"; print "<BR>Line $z<BR>"; } if (defined $elements[ 3 ] && defined $refList->{$elements[3]}) { print "<Br>Match<BR>"; } else { print "<BR>No match<BR>"; print NEW_ALIGN $alignment->{$z} . "<BR>"; print NEW_ACC $elements[3]."<BR>"; print $alignment->{$z} . "<BR>"; print $elements[3]."<BR>"; } } #close files close REF_FILE; close BLAST_FILE; close NEW_ALIGN; close NEW_ACC; }
I know the code is working upto the file opening as it prints the details on the screen, but when it gets to the BLAST_FILE open statement it produces an error saying "Content-type: text/html Software error: No such file or directory at BlastTool.cgi line 77. For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error."
Any ideas - im currently using (fatalstobrowser) and other error checking properties but no idea why.
Cheers, MonkPaul.
UPDATE:: I have changed the \n to \\n and the =~ to =
Janitored by holli - added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cannot open files using CGI
by injunjoel (Priest) on May 28, 2005 at 20:54 UTC | |
by MonkPaul (Friar) on May 28, 2005 at 21:30 UTC | |
|
Re: Cannot open files using CGI
by thundergnat (Deacon) on May 28, 2005 at 21:16 UTC | |
|
Re: Cannot open files using CGI
by graff (Chancellor) on May 29, 2005 at 02:34 UTC | |
by MonkPaul (Friar) on May 29, 2005 at 14:44 UTC | |
by graff (Chancellor) on May 30, 2005 at 00:51 UTC | |
by MonkPaul (Friar) on May 30, 2005 at 11:30 UTC | |
by graff (Chancellor) on May 30, 2005 at 15:54 UTC | |
by Anonymous Monk on May 30, 2005 at 12:01 UTC | |
|
Re: Cannot open files using CGI
by thcsoft (Monk) on May 29, 2005 at 01:44 UTC | |
by b10m (Vicar) on May 29, 2005 at 11:41 UTC |