Upon much inspection of the real world, and internal meditation; I find I fail at determining when a file I have open has been deleted/renamed. In attempting to use the:
seek(ML, 0, 1); # reset end-of-file error
technique to 'tail' a file, I need a test to determine when the file has been closed (during log rotation, for example) and need to close/reopen the file name.
require "stat.pl"; ... for(;;) { open ML, "</var/log/local2" || die $!; &Stat(ML); $old_ML_size = $st_size; #seek(ML, 0, 2); # to EOF - Not, process from beginning for (;;){ &Stat(ML); if ($old_ML_size > $st_size) { print "closing the file\n"; last; #file closed and new one started }else{ $old_ML_size = $st_size; } while (<ML>){ another_line(); } sleep 5; seek(ML, 0, 1); # reset end-of-file error } close(ML); }
Repeated 'Stat' has not worked for me.
Must I depend upon someone else to signal me that the world has changed?

In reply to Reading from a deleted file is futile by Wiggins

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.