Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!mcnc!uvaarpa!mmdf From: eichin@apollo.com Newsgroups: comp.lang.perl Subject: "comparing bitmasks" Message-ID: <1990Oct26.182652.13422@uvaarpa.Virginia.EDU> Date: 26 Oct 90 18:26:52 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: eichin@apollo.com Organization: The Internet Lines: 38 I'm using select to wait for a collection of file descriptors. I build masks $rin and $win: @fdnames=(F1,F2,F3,F4,F5,F6,F7,F8,F9,F10); foreach(@fdnames) { $tin = ''; vec($tin,fileno($_),1) = 1; if($mode{$_} eq "writewait") { $win = $win | $tin; } if($mode{$_} eq "readwait") { $rin = $rin | $tin; } } $nfound = select($rin,$win,undef,undef); The question: how do I check which bits are set (ie which filehandles are available for read or write)? I have a similar loop, which does ($win & $tin) and checks it, but what is the right way to check? ($win & $tin) is always true. In fact, I tried a few tests (setting $xx=$foo & $bar), and found the following were *always* true: if($xx) if($xx == 0) if($xx eq "") if(defined($xx)) throwing in a ($vxx)=unpack("c",$xx) made if($vxx) true as long as the bit being masked was less than 8 (ie in the first byte, which make sense...) What I finally got to work was testing if(($rin & $tin) eq $tin) It seems to work even when vec($tin,$x,1)=1 for $x>8, so it isn't bothered by intervening nulls. However, this behavior isn't hinted at in the manual page (it should probably be mentioned in the select example.) _Mark_