Hello everyone,

Can anyone pleaaase tell me what the most secure method of flocking is, or know of? I'm so lost, and going out of my mind :(

I started a thread here, and I was so thankful that mirod had answered me, and I thought my troubles were over :) Unfortunately I'm still having trouble with this. I left my last post there on March 12th, which I think has gotten lost with all the other posts, since no one has answered, and I don't know how to bump it up :)

I've been trying to read everything I could here and have managed to find these:

Everyone seems to have their own ways of doing this, and after reading and trying to understand, I've stayed on with KM's way of file locking. But as I said with my last post it still does not work.

What could I possibly be doing wrong? I also use this method as well.. is this wrong?

Example::

$SEMAPHORE = $tempfile . '.lck'; open(S, ">$SEMAPHORE") or die "$SEMAPHORE: $!"; flock(S, LOCK_EX) or die "flock() failed for $SEMAPHORE: $!"; open (TEMP, ">$tempfile") or die "Can't open $tempfile: $!"; open (FH, "$file") or die "Can't open $file: $!"; while (<FH>) { ## do_something; } close FH; close TEMP; rename($tempfile,$file); close S;
From what I understand this method should be locking all the files that are being read/written to? or Have I misunderstood? Both examples I have used still wipes my file clean every so often :(

Sorry for the long post, I feel like an idiot :(
Thanks so much

PS.. Is there a way to search the posts here on the monastery? Using the search box that appears at the tops of the pages just locates the perl man explainations.


In reply to flock() ..I really need a hand .. please :) by Anonymous Monk

Title:
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, details, 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, summary, 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.