The problem is a bit under-specified. The cycle to test a resource (read value, sleep, read value, sleep, etc.) is correct. Well, assuming that your print inside foreach is just a placeholder and you actually do some processing there such as getting the size and doing something with the file if size ... (your criteria here).

What is not clear is what you mean by "the file has stopped growing". I hope you don't conclude "hard disk full" when this happens... The semantics and dynamics of log file access are not known in your problem description. Based on what I read, the only thing that can be improved it fine-tuning the sleep interval ("stopped growing" means two consecutive reads yield the same size? or size doesn't change in 5 minutes? it is not clear ...). If you want the file to be moved when it reaches a certain size (popular option in handling logs), you can fine-tune your sleep based on the file growth speed (oh, well, not always easy to guesstimate, depending on the use scenario ...) and just move the file the first time it exceeds your size limit (that would be checked for in the foreach body.

Hard to give more details/opinions with only the info you provided, but your approach is good.


In reply to Re: automated file move by RaduH
in thread automated file move by scopey

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.