in reply to Writing to files

Two comments: use Fcntl qw(:flock); and write flock FILE, LOCK_EX; instead of using the cryptic magic values. Also, don't unlock a locked file, ever, unless you know what you're doing - just close it and the lock will go away.

Did you check your error logs? Is the scripting dieing at the open? Btw, you should prefer the three argument form: open(FILE, ">>", "/data.txt").

If not, does your platform support flock at all? There should be something about that in your error log as well if that's the case.

Update: Also, why not use CGI.pm's perfectly fine cookie-generation functions?

print header(-cookie => cookie( -name => $name, -expires => $expires, -path => $path, -domain => $server_domain, -value => "there is none in your example", ));

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: Writing to files
by diotalevi (Canon) on Dec 17, 2002 at 19:41 UTC

    Also, don't unlock a locked file, ever, unless you know what you're doing - just close it and the lock will go away.

    I'm inexperienced with flock and am now wondering what's going on here. Do you have an URL handy that explains why you don't unlock a file prior to closing. Or... *brainflash* buffering? Unlocking a handle doesn't flush the buffer so it introduces a race condition unless the handle is either hot (and autoflushed) or has been pre-flushed?

      Ding ding ding!! Bingo. :-) See also Don't use unflock (flock 8). Ever. by merlyn.

      It isn't a 100% valid concern anymore since 5.8 (or probably 5.7) and newer Perls make sure to flush and sync when unlocking, but you may still run on an older Perl (I write code for 5.6.1 and many people haven't gotten past 5.5 yet).

      Makeshifts last the longest.