I think the can_read()'s timeout, which is the same for both executions in the pipeline, is the culprit. Perhaps you could add a switch for the user to tell the script that it is either in read or write mode?

Edit: what I mean is that both scripts in the pipeline upon execution wait for at most 0.5s for piped input. That stops the 1st script from outputting anything to be passed to the 2nd script. They are run one after the other with a tiny time difference. Will this difference be enough for the 1st script to output and the 2nd to still be blocked in the can_read()? To see that, clone your test.pl and run the 1st with smaller timeout than the 2nd. Re: debugger, I can not explain what you experience. But I am sure that in this particular case, loading different libraries is not relevant.

I can't resist offering this halfway measure (don't take it seriously hehe): use a random timeout (can_read(rand)). In this way your pipeline will work correctly half the time, on average (given only 2 items in the pipeline). Correction edit: can_read(0.5+rand)

If you are a die-hard "do-what-i-mean" perl hacker and insist on not using CLI switches, then here is a tip: in the pipeline perl test.pl | perl test.pl, pid of 1st script (left, from where I see it) < pid of 2nd script (right). (print "my pid is $$\n:";)

1min Edit: Oh, I just remembered that in linux there is the -t test to check if your STDIN is associated with a terminal (your 1st script in the pipeline is, the second is associated with the output of the 1st script). And yes, just checked that in Perl you can do: if( -t STDIN ){ print "$$: not piped\n" } else { print "$$: piped\n" }.

And by the way, IO:Select's doc states also how to use the handle(s) which can_read() returns as ready for reading, and that's the handles you should use (instead of using raw "STDIN").

bw, bliako


In reply to Re: IO::Select woes by bliako
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.