Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Your examples on file locking to avoid race conditions all have race conditions themselves. Let's go over some of what you wrote:

First, some people do say 'eff-lock' :) Most things looked ok until the All about flock section. The concepts of LOCK_* is somewhat explained, but these values are constants which should be retrieved from the system header file which defines them. You should not define them in the script or create subroutines to do this. On an aside, you showed:

sub LOCK_SH { 1 } ## shared lock
sub LOCK_EX { 2 } ## exclusive lock
sub LOCK_NB { 4 } ## non-blocking
sub LOCK_UN { 8 } ## unlock
If you want to define a constant, you should include the prototype () like:

sub LOCK_SH () { 1 } ## shared lock

That's one way to make a constant, but.. back to the show..

One of the best ways to get these values is with the Fcntl module like:

use Fcntl qw(:flock);

This will import your systems constants for those values. The next example given contains a race condition. Actually, the way you are explaining to get around a race condition, is really also a race condition. Not to worry, many people make this mistake and think that a simple flock() will make everything watertight. One of the problems is that the system itself may not finish writing to the file when the actual lock is released (remember, locks are only advisory, a file isn't actually frozen in some way), and another process reads the file before the write is comeplete. This may be a rare occasion, however. Another problem can occur when another process updates the file between the time the file is opened, and the lock is obtained. This is ano

In reply to RE: File Locking by KM
in thread File Locking by turnstep

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [marto]: List EXE_FILES installed by CPAN so a couple of people suggest that your code looks obfuscated. I'd have to ageree, from the perspective of those who can't follow all of that one liner, it doesn't read well
    Veltro is a weirdo, obsessed with whitespace
    [marto]: to use the word "obsession" when so few people have said so little about it is grasping at staws
    marto wishes tye was around, he's so much better at this sort of thing
    usemodperl likes tye!
    usemodperl tye  too
    [choroba]: Re^3: LiBXML: New markup while preserving earlier tags? would benefit from a couple of test cases
    usemodperl meant tye&nbsp;
    usemodperl pokes Veltro with line noise
    usemodperl will try to make better shapes with his line noise, like a camel, or boobs, then it will be called "clever" :-)

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (8)
    As of 2018-06-24 16:01 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.