# info > IO::Select

---
type: CommandReference
command: IO::Select
mode: perldoc
section: 3
source: perldoc
---

## Quick Reference
- `$sel = IO::Select->new(@handles)` — create a new selector object
- `$sel->add($handle)` — register a handle (IO::Handle, integer, or arrayref)
- `$sel->remove($handle)` — unregister a handle by fileno
- `@ready = $sel->can_read($timeout)` — get handles ready for reading
- `@ready = $sel->can_write($timeout)` — get handles ready for writing
- `($r, $w, $e) = IO::Select->select($s_r, $s_w, $s_e, $timeout)` — static multi-set select

## Name
[IO::Select](https://perldoc.perl.org/IO::Select) — OO interface to the `select` system call

## Synopsis
perl
use IO::Select;

$s = IO::Select->new();
$s->add(\*STDIN);
$s->add($some_handle);

@ready = $s->can_read($timeout);

@ready = IO::Select->new(@handles)->can_read(0);
## Methods
- `new([HANDLES])` — constructor; optionally initialises with a list of handles.
- `add(HANDLES)` — registers handles. Accepts [IO::Handle](https://perldoc.perl.org/IO::Handle) objects, integers (fileno), or arrayrefs; duplicate fileno entries overwrite.
- `remove(HANDLES)` — unregisters handles by fileno. Exact original handle not required.
- `exists(HANDLE)` — returns the handle itself if registered, `undef` otherwise.
- `handles` — returns an array of all registered handles.
- `can_read([TIMEOUT])` — returns array of handles ready for reading. `TIMEOUT` in fractional seconds; blocks indefinitely if omitted and handles exist. On timeout, empty list with `$!` unchanged; on error, empty list with `$!` set. Distinguish by zeroing `$!` before the call.
- `can_write([TIMEOUT])` — like `can_read`, but for writability.
- `has_exception([TIMEOUT])` — like `can_read`, but for exception conditions (e.g., out-of-band data).
- `count()` — returns the number of handles that will be checked.
- `bits()` — returns the bit string suitable for the core `select()` call.
- `select(READ, WRITE, EXCEPTION [, TIMEOUT])` — **static method**. `READ`, `WRITE`, `EXCEPTION` are `undef` or [IO::Select](https://perldoc.perl.org/IO::Select) objects. Returns an array of three arrayrefs (ready handles for reading, writing, exceptions). On timeout, empty list with `$!` unchanged; on error, empty list with `$!` set.

## Examples
perl
use IO::Select;
use IO::Socket;

$lsn = IO::Socket::INET->new(Listen => 1, LocalPort => 8080);
$sel = IO::Select->new( $lsn );

while(@ready = $sel->can_read) {
    foreach $fh (@ready) {
        if($fh == $lsn) {
            # New connection
            $new = $lsn->accept;
            $sel->add($new);
        }
        else {
            # Process socket
            # ...

            # Cleanup when done
            $sel->remove($fh);
            $fh->close;
        }
    }
}
## See Also
- [IO::Handle](https://perldoc.perl.org/IO::Handle) — base class for I/O handles
- [IO::Socket](https://perldoc.perl.org/IO::Socket) — object interface to sockets
- [select(2)](https://man7.org/linux/man-pages/man2/select.2.html) — system call documentation