in reply to Order of flock and open

flock requires a filehandle in its argument list. How do you get a filehandle without opening it first?

I don't think it's as dangerous as it seems. Be default, flock blocks execution until the lock is actually obtained, so even though the file is open, you can't do anything potentially dangerous until you already have the lock. Someone more familer with low-level systems stuff would have to confirm this, though.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Order of flock and open
by halley (Prior) on Apr 30, 2003 at 16:29 UTC

    This highlights a difference of perception that is important: many people read flock() as "protect me from all those other bad programs out there," when it's actually intended as more of a "protect any of the other programs from the ruckus I'm about to cause."

    --
    [ e d @ h a l l e y . c c ]