JupiterHost.Net wrote:
Howdy list :)

I'm having a bit of a time with combining 2 read filehandles.
[snip]

What I'd like to do is process $read_fh and $error_fh in the order they actually happen ( which is what open3($write_fh, $read_fh, $read_fh, ... does ) but still have the error handle available afterward to look upon specifically.

I didn't test this so don't assume it will work, but I think it should ;-)

eof should return true if there is nothing left to read. So, instead of using <> which will block until there's something to read (or the fh is closed), you could periodically test eof on your file handles. Perhaps something like:

sub eof_and_read {
        if (eof ($_[0])) {
                return '';
        } else {
                return <$_[0]>;
        }
}


Simply replacing while (<blah>) with while (eof_and_read(blah)) won't work too well though; you'd have to check if the file is open. The way to do that (that I have found) is to tell, which will return -1 if the fh doesn't really exist or is closed. (I recommend adapting this to avoid warnings where you know there will be warnings, such as tell ($fakefh).)

e.g.,
sub isopen {
        no warnings; # tell() on unopened filehandle
        return tell (shift) > -1;
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to