Always check your error status $!
of open
or include use autodie
at the top of your script. You're calling open
but assuming it works. Because you're missing path information for the files, it's likely that they aren't being found and are all being skipped by the -r
check.
One solution for getting the path info included is to just use a file glob
instead of readdir
use strict;
use warnings;
use autodie;
use Digest::MD5;
my $dirname = "./directory_name";
foreach my $file (<$dirname/*>) {
next if -d $file;
open( my $FILE, '<:raw', $file );
print Digest::MD5->new->addfile($FILE)->hexdigest, " $file\n";
}
Additionally, be sure to open
your files in :raw
or binmode
or they may return incorrect values.