Perl Programming/Keywords/binmode

Previous: bind Keywords Next: bless

The binmode keyword

edit

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
  binmode FILEHANDLE, LAYER
  binmode FILEHANDLE
Previous: bind Keywords Next: bless