Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: What do you do after you've done select(2)? Message-ID: <1991May3.174432.1133@jpl-devvax.jpl.nasa.gov> Date: 3 May 91 17:44:32 GMT References: <1180015@hpcc01.HP.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 32 In article <1180015@hpcc01.HP.COM> okamoto@hpcc01.HP.COM (Jeff Okamoto) writes: : I have a question about the select(2) emulation in perl. : : There are plenty of places that explain how to set up for the call to : select, using fileno and vec to build the bitmap. What those same examples : DON'T provide is a good way to determine which file handle(s) are ready for : each operation. : : One way that I have seen, after going back through the archives is to keep : an associative array with the names of the file handles and their fileno() : values. What I am wondering is, is there a better way? It depends on how many filehandles you're managing. For a few filehandles, polling the vector from an associative array is probably reasonable. For lots of filehandles, I'd make a back-translation table: $handle[fileno(STDOUT)] = 'STDOUT'; and then I'd unpack the vector and search it: $nfound = select($rout = $rin, $wout = $win, $xout = $xin, $timeout); $bits = unpack('b256', $rout); for ($fd = index($bits,'1'); $fd >= 0; $fd = index($bits,'1',$fd+1)) { $handle = $handle[$fd]; if (defined $handle) { # do input using indirect filehandle or type glob } } and similarly for $wout and $xout. Larry