I think there is a confusion here between what the first process is doing and what the second process is doing.

I think your intention was that the first process prints the table, and the second process reads it; however both are running the same code, so in the normal course of events the first process sees nothing to read, so does not dump its table; since it outputs nothing, the second process also sees nothing to read, and also does not dump a table.

When you add print "checking pipe\n";, the first process outputs that, sees nothing to read, and exits. The second process now does see something to read - the diagnostic emitted by the first process - so it now calls dumpTable().

The first thing I would suggest to reduce confusion is to use "warn" rather than "print" for your diagnostics, so that they show up on STDERR and not on the pipeline; it may also be useful to show the process id ($$) in those diagnostics, so that you can distinguish the two processes.

I'm not familiar with the debugger, but since it will try to use STDIN to get console input it is certainly likely to confuse the issue.

I tested this with the code below:

% cat t0 #!/usr/bin/perl use strict; use warnings; use IO::Select; $|=1; warn "pid $$ checking pipe\n"; my $s = IO::Select->new(); $s->add(\*STDIN); if ($s->can_read(.5)) { warn "pid $$ can read\n"; print "here is my table\n"; } else { warn "pid $$ cannot read\n"; } % ./t0 | ./t0 pid 24811 checking pipe pid 24810 checking pipe pid 24811 cannot read pid 24810 cannot read % echo "go" | ./t0 | ./t0 pid 26452 checking pipe pid 26452 can read pid 26453 checking pipe pid 26453 can read here is my table %

Update: remove unneeded '(a)'


In reply to Re^2: IO::Select woes by hv
in thread IO::Select woes 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.