Is there any simple means to take lines off of the top of a file without rewriting the entire file? Or better yet, is there any way to tell how big a file will be once a string is added to it?

Short answer the first: no. Longer answer, see:

Found in /usr/lib/perl5/5.6.1/pod/perlfaq5.pod How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?

A file is an ordered stream of octets. Lines are just an illusion imposed by convention.

As for the second, presuming you're not mucking about with the file pointer and seek()ing about you can use tell() to find out where you are. That and the ever useful + operator along with length( $your_line ) should let you know. If you don't have the file open, -s/stat() would be where to look.

Update: Someone had mentioned -s/stat(). /me wanders off to get some Windex to clean the monitor and his glasses.


In reply to no one's fielded these yet by Fletch
in thread Limit a filesize by Flame

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.