I used read specifically because it is more flexible than getc

I don't see how read is more flexible than getc at reading available characters in the pipe. sysread is more flexible since it can read multiple characters in addition to reading a single character. This also makes it much faster IIRC.

I used read specifically because it [...] does interact properly with buffering if there is any.

That means you specifically didn't chose sysread because it doesn't interact properly with buffered IO, yet one is much more likely to encounter unbuffered IO than buffered IO when dealing with pipes (because the former solves the OP's problem and it's required by select).

but sysread may be preferable if bypassing buffers is desired as a rule.

That's backwards. I didn't use sysread to bypasses buffers, buffers aren't used because I used sysread. In the rare circumstance that other code reads from the pipe, non-buffered IO will have to be used there too, but that's not likely to be a problem. In the much more likely circumstance that select is used on the pipe, you'd need sysread anyway.

As an aside, although there is for perl 5.10.1 and 5.12.0 a note at the bottom of the entry for sysread in the perldocs about UTF and characters,

Basically, it says sysread will work with character streams as well as byte streams. I don't see why I should be pointing that out.


In reply to Re^6: Nested line buffered output by ikegami
in thread Nested line buffered output 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.