I have a file that is being used to lock a process that contains only the values of 1 and 0 in it. I have tried opening the File and $value = <file_name> as well as foreach(<file_name>){$value = $_}. I do not only want to `cat $file_name` because if the file is unreadable I want to be able to trap the error. What are my alternatives? I need to be able to do the following but for some reason it is not working...

STAGE_DIM: if(not(open(process_lock, "+>$proc_lock"))){ goto STAGE_DIM; sleep 1; } $lock_val = <process_lock>; #`cat $proc_lock`; print "Value=*$lock_val*\n"; if( $lock_val == 1) { close(process_lock); sleep 1; goto STAGE_DIM; } else { ... }

The Value read is always "". The only way thus far, I have been able to read the contents of the file was to $lock_val = `cat $proc_lock`; but this leaves the chance that the file could be unreadable because another Process has it locked open. Any ideas would be appreciated. Thanks. rheaton


In reply to File Read by rheaton

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.