Jump to content

Perl Programming/Keywords/binmode

From Wikibooks, open books for an open world
Previous: bind Keywords Next: bless

The binmode keyword

[edit | edit source]

The binmode function sets that FILEHANDLE is read or written in "binary" or "text" mode on systems where the run-time libraries distinguish such file types. If FILEHANDLE is an expression, its value is taken as FILEHANDLE name. The function returns true on success and undef otherwise, setting $! (errno). It is good programming practice to use it where appropriate and never to use it otherwise, as a missing call will result in errors on operating systems like DOS or Windows that differentiate such file types.

If LAYER is present, it is a single string that may contain multiple directives, which alter the behaviour of the FILEHANDLE. With LAYER, using binmode on a text file makes sense. Without LAYER or specified as :raw, the filehandle is made suitable for passing binary data. This includes turning off possible CRLF translation and as opposed to Unicode characters, marking it as bytes.

Syntax

[edit | edit source]
  binmode FILEHANDLE, LAYER
  binmode FILEHANDLE
Previous: bind Keywords Next: bless