Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am working on comparing (2) hashes of filenames/md5sum combinations, and I am stuck...What I am doing is using File::Find to get a recursive list of the files from the given(command line parm) dirs, both source, and destination. then I want to md5 all the files that I just made the list of. That is working fine, and here is what I have right now, with the error in the foreach loop.
my %sdirdigest{ "c:/temp/filename.txt"=>"4eb788842f1253903e16a1a0cfe +46f2f", "c:/temp/level2/filename2.txt"=>"fb3e103dee9f40881fb +e8fdccdc4d07a" }; my %ddirdigest{ "e:/temp/filename.txt"=>"4eb7adfaaf1253903e16a1a0cfe +46f2f", "e:/temp/level1/filename2.txt"=>"1fbe8fdccdc4d07afb3 +e103dee9f4088" }; foreach my $key (keys %sdirdigest) { print "Checking $key..." if $verbose == 1; if ((defined($ddirdigest{$key})) && ($sdirdigest{$key} eq $ddirdige +st{$key})) { print "SYNCHRONIZED...\n" if $verbose == 1; } else { print "UPDATING...\n" if $verbose == 1; my $todo = 'cp "'.$key.'" "'.$key.'"'; system($todo); } }

I know that the issue here is that I am using $key wrong, which is from when I was not doing a recursive check, if that makes sense. I am pretty sure that my issue is from design problems, but I am not sure what I need to do. I tried searching, but came up empty handed, due to the fact that I am not really sure what I need to do here. I don't need the answer specifically, just a pointer in the right direction. If I need more information, please let me know what will help.

update: Updated with the rest of my code.
#!/usr/bin/perl use warnings; use strict; use diagnostics; use Cwd; use File::Find; use Digest::MD5; use File::Basename; use Getopt::Long; my %fdirdigest; my %sdirdigest; my $fdircount='0'; my $sdircount='0'; my($fbn,$fdn,$fdg,$bn,$dn,$dg,@fdir_list,@sdir_list); my $fdir=''; my $sdir=''; my $recursive='0'; my $verbose='0'; GetOptions( 'verbose'=>\$verbose, 'recursive'=>\$recursive, 'src=s'=>\$fdir, 'dst=s'=>\$sdir ) or die "Oops, check your command line pa +rms. $^E"; if (!(-e $fdir && -e $sdir)) { print 'I can not proceed, since both dirs do not exist.'."\n"; exit(); } if ($recursive == 1) { find(\&push_to_fdir,$fdir); find(\&push_to_sdir,$sdir); } else { @fdir_list = glob("$fdir*"); @sdir_list = glob("$sdir*"); } foreach my $filef (@fdir_list) { if (-d $filef) { next(); } my $fdg; $fbn=basename($filef); $fdn=dirname($filef); chdir($fdn); my $fmd5 = Digest::MD5->reset; open(FILE,$fbn) or die "Unable to open the file: $^E\n"; binmode(FILE); while (<FILE>) { $fmd5->add($_); } close(FILE); $fdg = $fmd5->hexdigest(); $fdirdigest{"$filef"}=$fdg; $fdircount++; } foreach my $files (@sdir_list) { if (-d $files) { next(); } my $dg; $bn=basename($files); $dn=dirname($files); chdir($dn); my $md5 = Digest::MD5->reset; open(FILE,$bn) or die "Unable to open the file: $^E\n"; binmode(FILE); while (<FILE>) { $md5->add($_); } close(FILE); $dg = $md5->hexdigest(); $sdirdigest{"$files"}=$dg; $sdircount++; } foreach my $key (keys %fdirdigest) { print "Checking $key..." if $verbose == 1; if ((defined($sdirdigest{$key})) && ($fdirdigest{$key} eq $sdirdige +st{$key})) { print "SYNCHRONIZED...\n" if $verbose == 1; } else { print "UPDATING...\n" if $verbose == 1; my $todo = 'cp "'.$key.'" "'.$key.'"'; system($todo); } } print "\nFiles Processed:\t$fdir\t$fdircount\n"; print " \t$sdir\t$sdircount\n"; sub push_to_fdir { my $dir = getcwd; my $fp = "$dir/$_"; #print "$fp\n"; push(@fdir_list, "$fp") unless $_ =~ /^\.$|^\.\.$|[T|t]humbs.db/ or + $fp =~ /\/\//; } sub push_to_sdir { my $dir = getcwd; my $fp = "$dir/$_"; #print "$fp\n"; push(@sdir_list, "$fp") unless $_ =~ /^\.$|^\.\.$|[T|t]humbs.db/ or + $fp =~ /\/\//; }

In reply to Handling Hash Comparison by omega_monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-05-23 15:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found