Returns the currently selected filehandle. If FILEHANDLE is supplied,
sets the new current default filehandle for output. This has two
effects: first, a
write or a
For example, to set the top-of-form format for more than one output channel, you might do the following:
FILEHANDLE may be an expression whose value gives the name of the actual filehandle. Thus:
Some programmers may prefer to think of filehandles as objects with methods, preferring to write the last example as:
- use IO::Handle;
If you want to select on many filehandles, you may wish to write a subroutine like this:
The usual idiom is:
- ($nfound,$timeleft) =
- select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
or to block until something becomes ready just do this
Most systems do not bother to return anything useful in $timeleft, so calling select() in scalar context just returns $nfound.
Any of the bit masks can also be undef. The timeout, if specified, is in seconds, which may be fractional. Note: not all implementations are capable of returning the $timeleft. If not, they always return $timeleft equal to the supplied $timeout.
You can effect a sleep of 250 milliseconds this way:
select behaves like select(2): it returns
-1 and sets
On some Unixes, select(2) may report a socket file descriptor as "ready for
reading" even when no data is available, and thus any subsequent
would block. This can be avoided if you always use O_NONBLOCK on the
socket. See select(2) and fcntl(2) for further details.