in reply to Re^2: Global variables question
in thread Global variables question
Untested, but I figure close to what you want...test, experiment, move forward with the advice you've gotten so far...
Perl "sees" something akin to this (below)... a bit harder to understand than the above?my $num_errors = 0; foreach my $file (keys %hash1) { if (!exists ($hash2{$file}) ) { print "file: $file doesn't exist in 2nd directory\n"; } elsif ($hash1{$file} ne $hash2{$file}) { print "md5 didn't match for $file\n"; # meaning that file in 2nd directory is not the # same as the file in 1st directory $num_errors++; } } print "total errors = $num_errors\n";
%x is a hash but "x" has no contextual meaning! %dirA is a hash of file names in directory A to checksums.
Even %dirA_files_to_checksums would be wayyyyyy better than %hash1. I guess %dir1 is also ok. The % means hash - give more contextual information!
PS: Yes, a hash tables for this purpose is going to be WAY more efficient than an array.my $num_errors=0;foreach my $file (keys %hash1){if (!exists ($hash2{$f +ile})){print "file: $file doesn't exist in 2nd directory\n";}elsif ($ +hash1{$file} ne $hash2{$file}){print "md5 didn't match for $file\n";$ +num_errors++;}}print "total errors = $num_errors\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Global variables question
by PerlScholar (Acolyte) on Aug 24, 2010 at 22:36 UTC | |
by Marshall (Canon) on Aug 26, 2010 at 18:43 UTC | |
by PerlScholar (Acolyte) on Aug 31, 2010 at 11:48 UTC |