in reply to Re: Re: Is it server configuration or my error ??
in thread Is it server configuration or my error ??

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.

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

      my beloved hacker I did everything you said regarding:
      open (COUNTING, ">/path/to/counter.txt") or die "Cannot open: $!\n";
      print COUNTING $myvar;
       close COUNTING;

      it did not help. This works perfectly on my computer, but it doesn't work on the server side. I am almost sure that the server administrator should set up something to allow I/O operations. He uses Apache server. What should we know to solve it?
      regards, sOKOle