Perl Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 5.00

binmode() - Opening Files for Binary Output

This section describes steps on how to open file for binary output using open(), binmode() and print() functions.

If you want to open a file and write binary data to it, you should use the following functions:

  • open() to open the file to a file handle.
  • binmode() to set the file handle to binary mode.
  • print() to write data to the file handle.
  • close() to close the file handle.

Note that the print() function can be used in both binary mode and text mode. In binary mode, print() will not convert \n to \r\n in Windows system.

Sections in This Chapter

binmode() - Opening Files for Binary Input

binmode() - Opening Files for Binary Output

Copy.pl - Copying Binary Files

Bin2Hex.pl - Converting Binary Data to Hex Numbers

Dr. Herong Yang, updated in 2008
binmode() - Opening Files for Binary Output