in reply to CGI script makes Internal Server-error
I.e.$_ = <RECORD>;
However, I would be irresponsible if I did not alert you to some other areas of potential difficulty with your code.open(RECORD, "$DATAFILE") or error_page_exit("Could not open datafile" +); $_ = <RECORD>; $val = $_; close(RECORD);
Now attempt to get an exclusive lock. If some other process has the lock, this simply waits until the lock is available:open RECORD, "+< $DATAFILE"
Now you can read the current value and modify it:flock RECORD, 2; # exclusive lock
Now here's another tricky part: you need to reset the read/write pointer back to the beginning of the file before you write:my $val = <RECORD>; chomp $val; $val++;
Now you can write the new value, and wrap up:seek RECORD, 0, 0;
More detail is available in the documentation of the open() and flock() functions. And be sure to read the open() tutorial. Also, FAQ 9 has a little info on debugging CGI scripts. In addition, you might find some useful info in the Perl Debugging Tutorial. Lastly, don't forget to check the QandASection: CGI programming section of Categorized Questions and Answers to see if similar questions have been answered before.print RECORD "$val\n"; close RECORD; # automatically releases the lock
|
|---|