robmueller,
I think I understand, but I want to be sure. At first I thought you only wanted the first x bytes of a line for each line discarding the rest:
while ( <FOO> ) { $_ = substr($_, 0, 1024); # other stuff }
Then after reading your documentation, it looks like you want to avoid this because the newline may be so far away that you fill up all your memory. In fact, it appears that you want to continue reading the line and not start on the next one. Most of the time, people would just say to do:
{ local $/ = \1024; while ( <FOO> ) { # stuff } } # or sysread FOO, $_, 1024; # keeping track of offset
But your module adds one "feature". If the value of $/ and the time new was called is found in the buffer, only the portion up to that is returned and the remainder is left in the buffer for susequent calls.

So instead of getting consistent results I may get 1024 bytes or 1 byte depending on where things fell? Doesn't seem like a very useful module to me but I could be way out in left field here. The reason sysread passes the scalar to store the results as one of the parameters is so that it can return the actual number of bytes read (0 if eof and undef if error).

Cheers - L~R


In reply to Re: Read a line up to a maximum length by Limbic~Region
in thread Read a line up to a maximum length by robmueller

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.