Hello,

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


In reply to Cannot open files using CGI by MonkPaul

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.