#!/usr/bin/perl
# version 0.2
# philip at shuman dot org
# http://www.shuman.org/scripts/
#
use Digest::SHA1;
use File::Compare;

@files = `find . -type f`;

foreach $file (@files)
{
   chomp($file);
   unless ( open( FILE, "<$file" ))
   {
      print "## Can't open $file : $!\n";
   } else {
      $ctx = Digest::SHA1->new;
      $ctx->addfile(*FILE);
      $digest = $ctx->hexdigest;
      print "$digest $file\n";

      push @{$hashes{"$digest"}}, "$file";
   }
}

print "\n";

foreach $digestVal ( keys %hashes )
{
   #print "$digestVal\n";

   if ($#{ $hashes{$digestVal} } > 0)
   {
      foreach $fileX (@{$hashes{$digestVal}})
      {
         foreach $fileY (@{$hashes{$digestVal}})
         {
            if (("$fileX" ne "$fileY") && compare("fileX","fileY"))
            {
               print "$fileX and $fileY are identical\n";
            }
         } 
      }
   }
}
