On Jul 4, 2:05 am, [EMAIL PROTECTED] (John W. Krahn) wrote:
>
> > I have  a script which contains 2 hashes of file names as the keys and
> > md5 sums as the values. I am looking for ideas on fast and efficient
> > ways to compare the 2 hashes in the manner of the pseudo code below
>
> Can you fill us in on the big picture?  Perhaps you need a hash of arrays
> where the keys are the md5 sums and the values are arrays of file names?

the base hash is an initial collection of current file names and check
sums.  the script is kind of a poor man's incremental backup. here is
a snippet. the files_db hash (base hash) comes from a file
--
my %files;
find sub {
        $path = $File::Find::dir;
        (my $tpath = $path) =~ s/^c:/$target/;
        mkpath ($tpath, {verbose => 1} ) unless -e $tpath;
        if ( -f ) {
               # copy any files that don't exists at all on target
              (my $tname = $name) =~ s/^c:/$target/;
              copy ($name, $tpath) and print "copying $name\n"  unless -e
$tname;

              open F,  $_ or do {
                      warn "Cannot open '$File::Find::name' $!";
                      return;
                      };

             binmode(F);
             my $digest = Digest::MD5->new;
             $digest->addfile(*F);
             my $sum = $digest->hexdigest;

            $files{$name} = $sum;
            if ( exists $files_db{$name} and ( $files{$name} ==
$files_db{$name} ) ) {
                                ####
                # **compare sums and do stuff here**
           }
            }

}, $dir;

--

i am not sure how hash of arrays will help as each key = 1 sum  and
vice versa
Thanks for your help and any suggestions
Jim



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to