home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _a82b03f4930e52a859d2d04c0b3422a4 < prev    next >
Text File  |  2004-06-01  |  647b  |  33 lines

  1. #! /usr/bin/perl -w
  2. # computes and prints to stdout the CRC-32 values of the given files
  3. use lib qw( blib/lib lib );
  4. use Archive::Zip;
  5. use FileHandle;
  6.  
  7. my $totalFiles = scalar(@ARGV);
  8. foreach my $file (@ARGV)
  9. {
  10.     if (-d $file)
  11.     {
  12.         warn "$0: ${file}: Is a directory\n";
  13.         next;
  14.     }
  15.     my $fh = FileHandle->new();
  16.     if (! $fh->open($file, 'r'))
  17.     {
  18.         warn "$0: $!\n";
  19.         next;
  20.     }
  21.     binmode($fh);
  22.     my $buffer;
  23.     my $bytesRead;
  24.     my $crc = 0;
  25.     while ($bytesRead = $fh->read($buffer, 32768))
  26.     {
  27.         $crc = Archive::Zip::computeCRC32($buffer, $crc);
  28.     }
  29.     printf("%08x", $crc);
  30.     print("\t$file") if ($totalFiles > 1);
  31.     print("\n");
  32. }
  33.