title: How to read an image in as a byte array using Perl?
body: <p>I have very little Perl experience. </p>
  
  <p>I need to read a binary image in and pass it to the <code>Image::ExifTool</code> module.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>use Image::ExifTool;
  
  my $exifTool = new Image::ExifTool; 
  
  open(IMAGE, $file) || die "Can't Open $file\n";
  binmode(IMAGE);
  
  my ($buf, $data, $n);
  while (($n = read FILE, $data, 4) != 0) {
    $buf .= $data;
  }
  
  #'.=' is concat
  print $file .= " test";
  
  $infob = $exifTool-&gt;ImageInfo(\$buf);
  
  foreach ( keys %$infob ) {
      print "$_ =&gt; $$infob{$_}\n";
  }
  
  close(IMAGE);
  </code></pre>
  
  <p>As far as I can tell, my above code reads in the reference file and appends at the byte level the binary data to <code>$buf</code>.</p>
  
  <p>As per the ExifTool documentation, you can pass an in memory reference to a file as a scalar var to the ImageInfo method -- this is done above.</p>
  
  <p>When executed, the Image::ExifTool module spits out the following:</p>
  
  <pre><code>Error =&gt; Unknown file type
  </code></pre>