I think that there is no need to do this conditionally inside the while loop. You could just as well do it after the while loop terminates.
However, I am not sure that your while loop is constructed correctly. What happens if
- The external process produces some of its output, then gets swapped out.
- Your while loop runs, finds some input and processes it & loops back.
- The external process has not yet had a timeslice, so it hasn't had the opportunity to produce the rest of it's output.
- The while loop tests can_read(), finds nothing available, so the loop terminates.
I've never had occasion to use IO::Select, so I have no idea if this is a realistic scenario. It's not clear to me whether can_read() means "The connection is still open so if you attempt to read you might get something" or "some data has been received, so if you read you will get something".
Maybe you already know that you while loop is ok as is.
The basic scheme of extracting the exit code from $? after calling waitpid seems correct to me.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.