can be constructed using C<fileno> and C<vec>, along these lines:
$rin = $win = $ein = '';
- vec($rin,fileno(STDIN),1) = 1;
- vec($win,fileno(STDOUT),1) = 1;
+ 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) = split(' ',$_[0]);
- my($bits);
- for (@fhlist) {
- vec($bits,fileno($_),1) = 1;
+ my @fhlist = @_;
+ my $bits = "";
+ for my $fh (@fhlist) {
+ vec($bits, fileno($fh), 1) = 1;
}
- $bits;
+ return $bits;
}
- $rin = fhbits('STDIN TTY SOCK');
+ $rin = fhbits(*STDIN, *TTY, *MYSOCK);
The usual idiom is:
is implementation-dependent. See also L<perlport> for notes on the
portability of C<select>.
-On error, C<select> behaves like select(2): it returns
+On error, C<select> behaves just like select(2): it returns
-1 and sets C<$!>.
On some Unixes, select(2) may report a socket file
O_NONBLOCK on the socket. See select(2) and fcntl(2) for further
details.
+The standard C<IO::Select> module provides a user-friendlier interface
+to C<select>, mostly because it does all the bit-mask work for you.
+
B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
or <FH>) with C<select>, except as permitted by POSIX, and even
then only on POSIX systems. You have to use C<sysread> instead.