1. Perl
  2. builtin functions
  3. here

binmode function - binary mode

Use the binmode function to change the filehandle to binary mode . Binary mode is a mode that does not automatically convert a line break when inputting/outputting files. Binary files such as images and videos must be input and output in binary mode.

binmode $fh;

This is an example to read an image file.

# Read image file
my $file = 'picture.png';

open my $fh, '<', $file
  or die "Cannot open'$file':$!";

binmode $fh;

my $size = -s $file;

my $read = read($fh, my $buffer, $size, 0);

die "Cannot read'$file':$!" unless defined $read;

close $fh;

Related Informatrion