=over =item select FILEHANDLE X This calls the L syscall with the bit masks specified, which can be constructed using L|/fileno FILEHANDLE> and L|/vec EXPR,OFFSET,BITS>, along these lines: my $rin = my $win = my $ein = ''; vec($rin, fileno(STDIN), 1) = 1; vec($win, fileno(STDOUT), 1) = 1; $ein = $rin | $win; If you want to select on many filehandles, you may wish to write a subroutine like this: sub fhbits { my @fhlist = @_; my $bits = ""; for my $fh (@fhlist) { vec($bits, fileno($fh), 1) = 1; } return $bits; } my $rin = fhbits(\*STDIN, $tty, $mysock); The usual idiom is: my ($nfound, $timeleft) = select(my $rout = $rin, my $wout = $win, my $eout = $ein, $timeout); or to block until something becomes ready just do this my $nfound = select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); Most systems do not bother to return anything useful in C<$timeleft>, so calling L|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context just returns C<$nfound>. Any of the bit masks can also be L|/undef EXPR>. The timeout, if specified, is in seconds, which may be fractional. Note: not all implementations are capable of returning the C<$timeleft>. If not, they always return C<$timeleft> equal to the supplied C<$timeout>. You can effect a sleep of 250 milliseconds this way: select(undef, undef, undef, 0.25); Note that whether L|/select RBITS,WBITS,EBITS,TIMEOUT> gets restarted after signals (say, SIGALRM) is implementation-dependent. See also L for notes on the portability of L|/select RBITS,WBITS,EBITS,TIMEOUT>. On error, L|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just like L: it returns C<-1> and sets L|perlvar/$!>. On some Unixes, L may report a socket file descriptor as "ready for reading" even when no data is available, and thus any subsequent L|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block. This can be avoided if you always use C on the socket. See L and L for further details. The standard L|IO::Select> module provides a user-friendlier interface to L|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does all the bit-mask work for you. B: One should not attempt to mix buffered I/O (like L|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or L|/readline EXPR>) with L|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by POSIX, and even then only on POSIX systems. You have to use L|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead. Portability issues: L. =back