I have a CGI script that (1) writes to a datafile, then (2) immediately reads that file in order to print to a webpage. The problem is that the changes I make (deletions, actually) do not "take" immediately. For example, if I delete record #150 (by using splice--backwards, if there's more than one record being deleted), the page refreshes and record #150 is still on the page (even though it's gone from the datafile). If I reload the page (not, in case you're wondering, by resubmitting the form data, which would try to re-delete the record), then and only then will record #150 be gone from the webpage.
Now here's the weird part (to me): this happens only with the last three records. Suppose the last three records are 'A', 'B', and 'C'. For each of the last three records, a different thing happens if I try to delete it:
If I delete record $array[-1], then on the webpage, nothing happens until I refresh (without resubmitting). Then and only then the record (in this case, 'C') disappears.
If I delete record $array[-2], or 'B', then on the webpage, the last three records read: 'A', 'C', 'C'. THEN if I refresh (without resubmitting), the last two records are (as originally expected) 'A' and 'C'.
Finally, if I delete record $array[-3], or 'A', then on the webpage, the last three records read: 'B', 'C', 'C'. And again, if I refresh, the last two records are instead, as originally expected, 'B' and 'C'.
Whenever I delete any of the records in the beginning or middle of the file (before the $array[-3] position), the item(s) immediately disappear(s).
My only thought after research is that it might have something to do with a needed file lock, but I don't know anything about that, and it sounds implausible anyway. (The datafile is written-to and closed before it is reopened for reading.)
Please expose what embarrassing error I have committed! Or, if you need more info, let me know.
--ghopper :-)
In reply to Datafile doesn't update before being read by ghopper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |