Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

binmode

Sets the I/O discipline (encoding layer) for a filehandle.

Configures the encoding layer on a filehandle. When called with just a filehandle, sets binary mode (disabling any CRLF translation, though Linux does not perform CRLF translation by default). When called with a layer string, applies the specified encoding.

Currently recognized layers:

  • :utf8, :encoding(UTF-8) – mark the handle as UTF-8
  • :raw, :bytes – mark the handle as raw bytes

Returns true on success, false on failure.

Synopsis

binmode(STDOUT);              # set binary mode (no CRLF translation)
binmode(STDOUT, ":utf8");     # set UTF-8 encoding layer
binmode(STDOUT, ":raw");      # remove all layers
binmode($fh, ":encoding(UTF-8)");

See Also

open, PerlIO, Encode