[thelist] Perl: Writing to file not working......

Dwayne dwayne at iconys.com
Fri Aug 10 17:24:42 CDT 2001


not that you don't have enough to think about, but there's a potential 
problem when you release the lock on your file:

> 	# Log the new player.
> 	open (LOGEMAIL, ">>email.txt") || die "Can't open email.txt file.";
> 	flock (LOGEMAIL, 2); # Locks the file
> 		print LOGEMAIL "$email|\n"; # write to file
> 	flock (LOGEMAIL, 8); # Unlocks the file
> 	close(LOGEMAIL);
> 	}

close() will automatically release the lock on your file, so you don't really 
need the flock(LOGEMAIL, 8). but the important thing is that close() makes 
sure all buffers are flushed. if another process opens your file in between 
flock(LOGEMAIL, 8) and close(LOGEMAIL), your data could get scrambled.

- dwayne




More information about the thelist mailing list