Article 8103 of comp.lang.perl: Xref: feenix.metronet.com comp.lang.perl:8103 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.utdallas.edu!hermes.chpc.utexas.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!cauldron!ra.csc.ti.com!enterprise!sunds From: sunds@asictest.sc.ti.com (David M. Sundstrom) Subject: Re: checking whether information is waiting in Message-ID: Sender: usenet@csc.ti.com Nntp-Posting-Host: enterprise.asic.sc.ti.com Reply-To: sunds@asictest.sc.ti.com Organization: Texas Instruments References: Date: Thu, 18 Nov 1993 15:09:18 GMT Lines: 38 In article 93Nov18010752@vegas.cs.brown.edu, jgm@cs.brown.edu (Jonathan Monsarrat) writes: > Hi! > > I have some a perl program that reads from a pipe, so FILEHANDLE is data being > generated on the fly. > > I'd like to be able to check whether any data is pending reading on FILEHANDLE. > > Can it be done in Perl? > > -Jon > p.s. yes, of course it can, and there's more than one way to do it! :) You can use the select call: vec($rin,fileno(FILEHANDLE),1)=1; if(select($rout=$rin, undef, undef, 0)) { ## data is ready } else { ## data is not ready } By changing the 4th argument of select to a nonzero number, you will block your process until a) data is ready or b) it times out according to the value you specified. A timeout of zero effects a poll. For more on select, see the Camel book. To understand the "vec" wizardy, browse the man page on select to understand the format of the arguments which you are passing it. -David Sundstrom Texas Instruments.