Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] FLOCK

Expand Messages
  • Jonathan Paton
    Luinrandir, I strongly suggest you evaluate the quality of information you are using. Read: http://www.perl.com/lpt/a/2000/06/27/perlbook.html And apply the
    Message 1 of 9 , Dec 22, 2004
    • 0 Attachment
      Luinrandir,

      I strongly suggest you evaluate the quality of information you
      are using. Read:

      http://www.perl.com/lpt/a/2000/06/27/perlbook.html

      And apply the tests to the article you are using in your support.
      No warnings, no strict, no checking of open/close, use of signal
      (the &) on function calls, unnecessary quoting of variables
      ("$var") are obvious signs of poor quality code.

      Perl is a mongrel language, with the best and the worst features
      of other languages... as well as some unique features of its own.
      Putting it all together is an art form, a novice can't be expected
      to produce high quality code.

      Peer review of your work by someone more experienced is a good
      way to learn alternative solutions. You have to be willing to accept
      advice though.

      I strongly recommend "Programming Perl" as your primary reading
      material. You will find that the different precedence of the logical
      operators (and, or, not, &&, ||, !) is mentioned on pages 26, 27 of
      the 3rd edition.

      Regarding flock(), resource (e.g. a file) locking is a challenging
      topic, and it is easy to be bitten by oversights and mis-
      understandings.

      Randal hasn't clearly explained his objection, but I think I know
      what he means. [WARNING: I have limited flock() experience]

      The first issue is that the open deletes the file contents, then
      you wait for your turn to modify the file. Whoops. By opening
      the file in append mode, you have the file open so you can wait
      for it using flock().

      However, once your turn comes, you have the file open but not at
      the beginning. Instead, it is open at some unknown byte in what
      is probably a non-empty file. To solve this new problem you
      go to the start (using seek) and then truncate the file (using
      trunc).

      I recommend reading more elsewhere, as Randal suggested.

      Jonathan Paton

      --
      #!perl
      $J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
      17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
      00+4 00+8 1-21 01+1 00+5 01-7 >=~/ \S\S \S\S /gx) {m/(
      \d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,
    Your message has been successfully submitted and would be delivered to recipients shortly.