use strict; use warnings; use Fcntl ':seek'; use constant CHUNK => 65536; sub calc { my $file = shift or die "no filename given\n"; my $hash = -s $file; my $chunk = CHUNK; $hash < $chunk and die "$file is too small ($hash bytes < $chunk)\n"; open my $in, '<', $file or die "Cannot open $file for input: $!\n"; local $/ = \$chunk; $hash += ord($_) for split //, readline($in); seek($in, SEEK_END, -$chunk); $hash += ord($_) for split //, readline($in); close $in; return sprintf '%016x', $hash; } print calc($_), "\t$_\n" for @ARGV;