
gregarios
stranger
May 23, 2002, 1:34 PM
Views: 2731
|
|
Re: [yapp] Database Unexpected Erasure Problem
|
|
|
Thanks... Ok, then. Judging from my original code seen here:#!/usr/bin/perl5 -wT use strict; $| = 1; if (!open (ADDCTX, "<ads.dta")) {die "Could not open file: $!";} flock(ADDCTX,1) or die "Could not lock file: $!"; seek(ADDCTX,0,0); my @ads = <ADDCTX>; close(ADDCTX); my @TLAD = split(/\|/,$ads[rand @ads]); $TLAD[2]++; $ads[$TLAD[0]] = "$TLAD[0]|$TLAD[1]|$TLAD[2]\n"; print "Content-type: text/html\n\n"; print "Advertisement: $TLAD[1]"; if (open (ADDCTZ, "+<ads.dta")) { flock(ADDCTZ,2) or die "Could not lock file: $!"; truncate ADDCTZ,0; seek(ADDCTZ,0,0); print ADDCTZ @ads; close(ADDCTZ); } exit; I've apparently done only a few things different: 1) Open a file only once in a given cgi when you wish to read, edit, then write back to it. 2) Use "use Fcntl qw(:flock);" in addition to the actual flock command and "LOCK_EX" style instead of the numeric equivelent. 3) Seek to the EOF when appending, which I am not. The file is a fixed number of lines and it stays that way. 4) Use "sysopen" instead of just the "open" command. Could you please tell me why each of these things makes a difference? I've really been trying to find out the details on this for some time but cannot find information about the "why's and wherefore's" of this stuff. Perldocs are only so good at telling you how to use certain things, but not so good as to the why's or when's. :-) • Greg J Piper • [url=http://www.macpicks.com]MacPiCkS
(This post was edited by gregarios on May 23, 2002, 1:37 PM)
|