I created a file that upon exit, tracks the exit point, so I know what happened... however, the file runs every 4 minutes. That is 15 times per hour and 360 times per day.

So, I want to track how many entries, I want to keep it at 100 entries, so I can look back for the past 6 and 2/3 hours, that should be good enough... So at the top of the file, I want to have it keep only the entries numbered 2-100, so it should strip out the first line only, so it will now be 1-99 then when it exists it will write line 100, so next time it will delete line 1 again, etc...

I don't know exactly how to do it effeciently though. I think there is a way to count the lines like this:
open(FILE,"/path/to/file.txt") or die "could not open file: $!"; my @_lines = <FILE>; # After I open the file for reading close(FILE); my $_numOfLines = scalar @_lines;# Is that right? I think it is, but m +y mind is rusty, been a while since I learned all of the perl program +ming
So if @_lines had 100 lines, can I not do a delete and have it remove only the first line and then just write the file again?

any ideas how how to do that?

Thank you kindly for any advice.

Richard

In reply to reading files 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.