Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
The stupid question is the question not asked
 
PerlMonks  

Re: (Ovid -flock) Re: File Use

by qball (Beadle)
on Apr 04, 2001 at 19:07 UTC ( [id://69804]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to (Ovid -flock) Re: File Use
in thread File Use

Only my program will be accessing the file. I just need to make sure it's not being used if someone else runs my program. I'm looking at flock now, but can it return true if the file is in use? qball-"I have node idea?!"

Replies are listed 'Best First'.
(Ovid - flock, part 2 )Re(3): File Use
by Ovid (Cardinal) on Apr 04, 2001 at 19:18 UTC
    Then you're in luck. You want an exclusive lock on the file:
    use Fcntl ':flock'; # import LOCK_* constants my $filename = "somefile.txt"; open FILE, ">>$filename" or die "Cannot open $filename for writing: $! +"; flock FILE, LOCK_EX or die "Cannot get exclusive lock on $filenam +e: $!";
    Just be sure not to forget to unlock the file when done. Plus, my code above is for appending, which is what I suspect you want.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69804]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.