< Perl Programming < Keywords

The binmode keyword

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

  binmode FILEHANDLE, LAYER
  binmode FILEHANDLE
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.