Perl-scripting HELP (140 Views)
Reply
Trusted Contributor
Stanimir
Posts: 321
Registered: ‎11-01-2001
Message 1 of 5 (140 Views)
Accepted Solution

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? :)

Honored Contributor
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 2 of 5 (140 Views)

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
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 3 of 5 (140 Views)

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
Stanimir
Posts: 321
Registered: ‎11-01-2001
Message 4 of 5 (140 Views)

Re: Perl-scripting HELP


Thanx, it works !!!
Frequent Advisor
Jeff Smith
Posts: 85
Registered: ‎09-13-2004
Message 5 of 5 (140 Views)

Re: Perl-scripting HELP

Thanks guys.. saved me some work.. I appreciate it!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.