Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

File Locking

by turnstep (Parson)
on Apr 06, 2000 at 22:33 UTC ( #7058=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    open(MYFILE, ">>$myfile") || die;
    flock(MYFILE, 2) || die;
    print MYFILE "Cottleston Pie\n";
    close(MYFILE);
    
  2. or download this
    
    #!/usr/bin/perl
    ...
    print "You are now in my list, $newfriend!\n"
    exit;
    
  3. or download this
      open(MYFILE, ">$myfile") || die;
    
  4. or download this
      flock FILEHANDLE, OPERATION
    
  5. or download this
      sub LOCK_SH { 1 } ## shared lock
      sub LOCK_EX { 2 } ## exclusive lock
      sub LOCK_NB { 4 } ## non-blocking
      sub LOCK_UN { 8 } ## unlock
    
  6. or download this
    
    #!/usr/bin/perl
    ...
    print "You are in my list, $newfriend!\n"
    exit;
    
  7. or download this
      flock(MYFILE, 1);
    
  8. or download this
      flock(MYFILE, 2);
    
  9. or download this
      open(MYFILE, "+< $myfile") || die;
    
  10. or download this
      seek(MYFILE, 0, 0); truncate(MYFILE, 0);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://7058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-07-06 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls