One-way comm:

use strict; use warnings; use IO::Select qw( ); use IPC::Open3 qw( open3 ); use Symbol qw( gensym ); sub launch { my ($id) = @_; open(local *TO_CHILD, '<', '/dev/null') or die $!; *TO_CHILD if 0; my $pid = open3( '<&TO_CHILD', my $from_child = gensym(), '>&STDERR', perl => ( -e => 'use Time::HiRes qw( sleep ); $|=1; for (1..rand +(10)+5) { sleep(0.100 + rand(100)/1000); print "a" }' ), ); return { id => $id, pid => $pid, pipe => $from_child, buf => '' }; } my %children = map { $_->{pipe} => $_ } map launch($_), 1..2; my $sel = IO::Select->new( map $_->{pipe}, values %children ); while ($sel->count) { for my $fh ($sel->can_read(0.050)) { my $child = $children{$fh}; our $buf; local *buf = \( $child->{buf} ); my $rv = sysread($fh, $buf, 64*1024, length($buf)); die $! if !defined($rv); if (!$rv) { delete $children{$fh}; $sel->remove($fh); waitpid($child->{pid}, 0); printf("%s: Exited with %08X after receiving %s\n", $child->{ +id}, $?, $buf); next; } printf("%s: Received some data\n", $child->{id}); } }
1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 2: Received some data 1: Received some data 1: Exited with 00000000 after receiving aaaaa 2: Received some data 2: Received some data 2: Received some data 2: Exited with 00000000 after receiving aaaaaaa

In reply to Re: Does IO::Select work? Anywhere? by ikegami
in thread Does IO::Select work? Anywhere? by BrowserUk

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.