1752290 Members
5130 Online
108786 Solutions
New Discussion юеВ

Re: Perl-scripting HELP

 
SOLVED
Go to solution
Stanimir
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? :)

4 REPLIES 4
H.Merijn Brand (procura
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
H.Merijn Brand (procura
Honored Contributor
Solution

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
Stanimir
Trusted Contributor

Re: Perl-scripting HELP


Thanx, it works !!!
Jeff Smith
Frequent Advisor

Re: Perl-scripting HELP

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