title: Removing files with duplicate content from single directory [Perl, or algorithm]
body: <p>I have a folder with large number of files, some of with have exactly the same contents. I want to remove files with duplicate contents, meaning if two or more files with duplicate content found, I'd like to leave one of these files, and delete the others.</p>
  
  <p>Following is what I came up with, but I don't know if it works :) , didn't try it yet. </p>
  
  <p>How would you do it? Perl or general algorithm.</p>
  
  <pre><code>use strict;
  use warnings;
  
  my @files = &lt;"./files/*.txt"&gt;;
  
  my $current = 0;
  
  while( $current &lt;= $#files ) {
  
      # read contents of $files[$current] into $contents1 scalar
  
      my $compareTo = $current + 1;
      while( $compareTo &lt;= $#files ) {
  
          # read contents of $files[compareTo] into $contents2 scalar
  
          if( $contents1 eq $contents2 ) {
              splice(@files, $compareTo, 1);
              # delete $files[compareTo] here
          }
          else {
              $compareTo++;
          }
      }
  
      $current++;
  }
  </code></pre>