You can read non blocking using select, and looping trough select until there is some data to read.
Reading using the diamond operator or sysread is blocking. The difference between the two is that using sysread you can control how much data to read at once.
Also, i see you are using cat some_file|consumer.pl, so i don't understand why you are looping and sleeping in consumer, as cat happens to give you data only once ;-) (if you "cat" a closed file)
I also think that you are using the wrong approach here. If you want the consumer to read data at certain amounts of time, a better approach IMHO is to do blocking reads in a while(1) without sleeping, and feeding the consumer at the needed intervals. I.E:
shell> for ((;;)); do cat /usr/share/dict/words;sleep 10 ;done |./cons +umer.pl
Note that by not running cat just once, you will not receive end-of-file, and as such you need to read using sysread from the consumer.
Dodge This!

In reply to Re^3: Read from a Linux pipe hangs. by Ultra
in thread Read from a Linux pipe hangs. by dmor4477

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.