sOKOle has asked for the wisdom of the Perl Monks concerning the following question:

such a simple code:
#!/usr/bin/perl open (COUNTING, "< D:\StronyKlientow\cematsil.bptnet.pl\main\Alicja\pe +rl\counter.txt")||die"can not open"; $count = <COUNTING>; close (COUNTING);
Always returns:
CGI Error The specified CGI application misbehaved by not returning a complete s +et of HTTP headers. The headers it did return are: can not open at D:\StronyKlientow\cematsil.bptnet.pl\main\Alicja\perl\ +counter.pl line 6.
Doesn't metter what directory path I write. Is the code wrong? Or server (Apache) is not configured properly? Perl scripts works properly if I do not require any file operations.
I suppose that it is something wrong with the server. Could you help?

Thank you in advance, Regards, sOKOle

Edit by tye

Replies are listed 'Best First'.
Re: Is it server configuration or my error ??
by amphiplex (Monk) on Jul 18, 2002 at 10:06 UTC
    Hi !

    You write that Perl scripts works properly if I do not require any file operations. .
    The code you posted does contain nothing else, please post the rest of the script, too.

    If this really is all of your script, then what would you want it to do ? As it is, it doesn't print anything.

    In order to return something from a CGI-Script that will appear in the browser calling your script, you will have to print a valid html file.
    Propably the easiest way to do this is to use CGI.pm.

    Here is a small example that will print the first line of your file:
    #!/usr/bin/perl use strict; use CGI; my $q = new CGI; print $q->header(); print $q->start_html(); open (COUNTING, "< D:\StronyKlientow\cematsil.bptnet.pl\main\Alicja\pe +rl\counter.txt") || die "can not open: $!"; my $count = <COUNTING>; close (COUNTING); print "count: $count"; print $q->end_html;
    BTW: Please use <CODE> tags when presenting code, this makes it much easier to read and download.

    ---- amphiplex
Re: Is it server configuration or my error ??
by rdfield (Priest) on Jul 18, 2002 at 10:09 UTC
    Try replacing the backslashes with forwardslashes...it looks like you have an interpolation problem.

    rdfield

      :))) thanks rdfield I can read the file now, BUT I CAN NOT WRITE TO IT. Full code below, it is the simplest CGI counter:
      #!/usr/bin/perl $number_of_digits = "6"; ###################### open (COUNTING, "< D:/StronyKlientow/cematsil.bptnet.pl/main/Alicja/pe +rl/counter.txt")||die"can not open"; $count = <COUNTING>; close (COUNTING); $count ++; print ("Content-type: text/html\n\n"); print "<HTML><BODY BGCOLOR=lightblue><TABLE ALIGN=center BORDER=0>\n\n +"; print "<TR><TD ALIGN=Center VALIGN=top>\n\n"; @digits = split(//, $count); # Give empty digits a value $spline = '%0' . $number_of_digits . 'd'; $count = sprintf("$spline", $count); @digitimages = split(//, $count); foreach $digitimage (@digitimages) { $image = "<img src=\"../obrazki/" . "$digitimage" . ".gif\" VSPACE=0> +"; print ("$image"); } print "\n"; print "</TD></TR></TABLE>\n</BODY></HTML>\n\n"; open (COUNTER, "> D:/StronyKlientow/cematsil.bptnet.pl/main/Alicja/per +l/counter.txt")||die"can not open!\n"; print COUNTER ("$count"); close (COUNTER); exit;
      whatever I do the counter do not increse. What should I do now?
      Thank you in advance, Regards, sOKOle

      Edit by tye

        Eek...please use <code> tags. To write to the file, you'll need to remove the < from before the "D:" - as it stands the code only opens the file for reading. You might want to have a look through perlfaq5.

        rdfield

        I should give the code more properly, here it is:
        #!/usr/bin/perl $number_of_digits = "6"; open (COUNTING, "< D:/StronyKlientow/cematsil.bptnet.pl/main/Alicja/pe +rl/counter.txt")||die"can not open"; $count = <COUNTING>; close (COUNTING); $count ++; print ("Content-type: text/html\n\n"); print "<HTML><BODY BGCOLOR=lightblue><TABLE <BR>ALIGN=center BORDER=0> +\n\n"; print "<TR><TD ALIGN=Left VALIGN=top>\n\n"; @digits = split(//, $count); $spline = '%0' . $number_of_digits . 'd'; $count = sprintf("$spline", $count); @digitimages = split(//, $count); foreach $digitimage (@digitimages) { $image = "<img <BR>src=\"../obrazki/" . "$digitimage" . ".gif\" VSPAC +E=0>"; print ("$image");} print "\n";
        open (COUNTER, "> D:/StronyKlientow/cematsil.bptnet.pl/main/Alicja/per +l/counter.txt")||die"can not open!\n"; print COUNTER ("$count"); close (COUNTER); print "</end of HTML TAGS \n</BODY></HTML>\n\n";
        exit;

        Edit by tye.