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
| [reply] [d/l] |