Showing results for 
Search instead for 
Do you mean 

Perl-scripting HELP

SOLVED
Go to Solution
Trusted Contributor Trusted Contributor

Perl-scripting HELP

Please a little help!
I'm trying to create hash named %ARR the result of command OS-command "cksum" in Perl script.

Something like:

%ARR=system( "cksum * | awk '{print \$1}" );

the (keys %ARR) must be = cksum's of files into current dir

the (values %ARR) must be = filename's of files into current dir.

Any examples? :)

1 ACCEPTED SOLUTION
Honored Contributor

Re: Perl-scripting HELP

for extra uniqueness, change that to


use Digest::MD5 qw( md5_hex );
use Digest::SHA1 qw( sha1_hex );
use File::Find;
my %arr;
find (sub {
-f or return;
local $/;
open my $p, "< $_" or die "$_: $!\n";
my $f = <$p>;
my $sum = md5_hex ($f) . sha1_hex ($f);
$arr{$sum} = $_;
}, ".");

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
4 REPLIES
Honored Contributor

Re: Perl-scripting HELP

# man Digest::MD5

use Digest::MD5 qw( md5_hex );
use File::Find;
my %arr;
find (sub {
-f or return;
local $/;
open my $p, "< $_" or die "$_: $!\n";
my $sum = md5_hex (<$p>);
$arr{$sum} = $_;
}, ".");

This will NOT check if there are more than one files with the same MD5

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Honored Contributor

Re: Perl-scripting HELP

for extra uniqueness, change that to


use Digest::MD5 qw( md5_hex );
use Digest::SHA1 qw( sha1_hex );
use File::Find;
my %arr;
find (sub {
-f or return;
local $/;
open my $p, "< $_" or die "$_: $!\n";
my $f = <$p>;
my $sum = md5_hex ($f) . sha1_hex ($f);
$arr{$sum} = $_;
}, ".");

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Trusted Contributor Trusted Contributor

Re: Perl-scripting HELP


Thanx, it works !!!
Frequent Advisor

Re: Perl-scripting HELP

Thanks guys.. saved me some work.. I appreciate it!