in reply to Is it server configuration or my error ??

Try replacing the backslashes with forwardslashes...it looks like you have an interpolation problem.

rdfield

  • Comment on Re: Is it server configuration or my error ??

Replies are listed 'Best First'.
Re: Re: Is it server configuration or my error ??
by Anonymous Monk on Jul 18, 2002 at 10:56 UTC
    :))) 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

        it is not < I tried
        open (COUNTER, "D:/StronyKlientow/cematsil.bptnet.pl/main/Alicja/perl +/counter.txt")||die"can not open!\n"; print COUNTER ("$count"); close (COUNTER);

        but it doesn't help. My suppose is that the administrator should open the possibility ... somehow...he uses Apache server.
        Please comment. I appreciete help, rgds rdfield

        Edit by tye

      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.

        A few style issues:
        • use strict; use warnings; use diagnostics;
          I can't stress that enough. Get into the habit early.
        • Use CGI.pm for your HTML output. It will make maintaining and updating your code much easier.

        • There is no need to double-quote your integers. You can safely say:

            $number_of_digits = 6;
        • Your check for success on open() should be written as:

            open (HANDLE, ">/path/to/file") or die "Cannot open: $!\n"
          Note my use of the 'write' redirection operator. The less-than operator is an explicit read, the greater-than is an explicit write.
        • You do not need to enclose your filehandle in parenthesis when you close it. This is sufficient:

            open (COUNTING, ">/path/to/counter.txt") or die "Cannot open: $!\n"; print COUNTING $myvar; close COUNTING;
        • If you were using CGI, you could transform the HTML you're using to something like:

          my $query = CGI->new; print header(), $query->start_html(-title=>'My Counter', -author=>'you@domain.com', -base=>'true' -background=>'#7fb6bb');
          You don't have to use 'lightblue' as your color also, and many browsers may not interpret that properly if used in that fashion. "How light is light?"
        • You open and close your counter.txt file twice in the course of this script. Why not open it once, read from it, leave the handle open, and then write your data to it, then close the handle. Much less IO on the server side.

        • Also, more CGI.pm here: print end_html();

        Maybe these tips will help you to discover your error.

        Edit by tye (CODE tags in BLOCKQUOTE = too wide)