Ok, I am playing around with forks and pipes and am trying to write from the parent process to a child process (created with Proc::Fork, which i adore), but the child will read from the pipe until it recieves and EOF. The only way I know to do this to send this is to close the pipe. In the rather terrible example below this lack of knowledge is fatal.

use Proc::Fork; use IO::Pipe; my ($pipe) = new IO::Pipe; child { $pipe->reader(); while (1) { while ($num = <$pipe>) { } print "Child: $num\n" if $old_num != $num; $old_num = $num; last if $num == 644; } exit; }; $pipe->writer(); while (1) { $in = <>; chomp $in; print $pipe $in; last if $in == 644; }

This outputs all the things I have sent over pipe together. It wont break them apart. When I enter 644 the parent dies (closing the pipe), and the child prints the string of numbers it recieved and then just goes on without a care in the world. I have tried putting lasts in the child while loop (ie.

While ($num = <$pipe>) {
    last;
}
and that doesn't work. Any ideas are more then welcome. For the record i have super searched and perldoc'ed IO::Pipe. Cant find the answer anywhere. I know if you use IO::Handle you can do something like $pipe->eof;, but know how to integrate IO::Pipe and IO::Handle.

INPUT:
5
62
345
23
644

OUTPUT:
Child: 56234523644

Desired OUTPUT:
Child: 5
Child: 62
Child: 345
Child: 23
Child: 644

In reply to Sending EOF to pipe by smgfc

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.