Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • select ($rbits, undef, $ebits, TIMEOUT);

    The first 3 arguments to select are value/return - on input you give a bitmask of the file descriptors you are interested in, on output only the bits corresponding "interesting" file descriptors are set. So it's likely that after the first call to select, all the bits were zeroed, and so for subsequent calls the arguments you passed in say that you're not interested in any file descriptors, so you never call any of your action functions. The solution is something

    • I know, and if you look at the code, it's setting $ebits and $rbits in each iteration. $BITS is set once, and it's not modified. Just before the select loop, $ebits and $rbits are initialized with $BITS.
      • Ah OK. So I was right when I had this hunch on hitting "Submit" that I'd missed something. :-)

  • Isn't there a module for this? Your mistake is in writing your own buggy code instead of using somebody's better tested module. :P

    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
    • I've no idea whether there's a module for this. But I'm pretty sure locating the module, reading the documentation, and convincing myself the module does what I want, and is bugfree would take longer than writing and debugging a few lines myself.
      • Speaking of wheels, this seems an ideal candidate for a POE [] session and POE::Wheel::FollowTail.

        • Somehow it feels wrong to install a rather large selection of modules only to shave off a few lines of a less than 100 line stand alone script.
          • ... specially if shaving off a few lines means writing others (probably as much as you've saved), from which at first glance you absolutely won't get what the heck they are about, and what's going on behind the scenes: that's the wrong way of abstraction.
    • Yes, it is called IO::Select, released with perl 5.3.7.
  • Obviously, you should be doing another_thing() in response to $p2 coming ready. I wish you wouldn't post such trivial problems.


  • Opening a pipe returns the pid. Don't you want to pass the filehandle, not the pid, to fileno()?
  • open [] does not return the filehandle, so it would appear that $p1 and friends are not what you seem to expect based on the rest of the code.

    • While that's a mistake in the fragment I gave, I didn't make that mistake in the program.
  • well, you never say what you expect it to do nor what it seems to do. this is a classic case of saying it doesn't work without saying anything else. you should know better than that! :)

    one issue i see is that you don't handle when a socket/pipe closes. without removing a closed handle from that data it looks like it may do an infinite loop of reading zero bytes.

    but the bug i see is the if( $ebits ) line. since $ebits is a char string and not likely be '0' or '', it will be true all the time. you need to eit