in reply to Perl counter in cgi-bin

You are not testing whether the open statements worked before continuing on.

Also, what is the point of the for loop? A simple print $data; should suffice since the numbers will all appear on one line once the funky stuff is removed (since you are not printing a <br />). The funky stuff that I mentioned are the curly braces and they are killing the script.

Here's your for loop with the curly braces removed (and a couple mys for good measure):

for ( my $count = 0; $count < length( $data ); $count++ ) { my $number = substr( $data, $count, 1 ); print( $number, "\n" ); }

Here is another way to do that loop (bonus! I added the <br />s):

for my $number (split //, $data) { print "$number<br />\n"; }

Someone is bound to say this if I don't.... You can even do it with a one-liner:

print "$_<br />\n" for (split //, $data);

 

Update: Rewrote the last sentence in the second paragraph for clarity.

Replies are listed 'Best First'.
Re^2: Perl counter in cgi-bin
by edeita2 (Novice) on Jun 05, 2004 at 20:05 UTC
    Dear friend, I have tried your solution, but still the same error "an error occurred while processing this directive" I think I have to find that directive first and correct or change then try the code, I`m gonna look at Apache conf. file god bless
      I didn't look at your code...You didn't mention anything about file permissions. Just in case you missed that part out, 'counter.dat' should be chmod'ed to 666 and your perl script to 755.