kzyz has asked for the wisdom of the Perl Monks concerning the following question:

Please help me sort out the following problem: I have to compare (bitwise) files in two directories and if there is found atleast one single file not present in the other directory, then the comparison fails and program aborts. (The two directories names needs to be supplied as arguments at command line) I have the following solution:
use strict; use warnings; use File::Find; use File::Compare; #use Data::Dumper; my $dir1 = '/home/khan/Desktop/dir2'; my $dir2 = '/home/khan/Desktop/dir1'; my %dir = (); my $file=''; find(\&wanted, $dir1,$dir2); sub wanted { my $f = $File::Find::name; next if $File::Find::name =~ /^\.{1,2}$/; $f =~ s/^($dir1|$dir2)//o; $dir{$1}{$f}++; # create a hash for each parent $dir{$f}++; # count all files in both parents } foreach my $parent ($dir1, $dir2) { foreach my $file ( sort keys %{$dir{$parent} } ) { print "Failed" if ($dir{$file} == 1); } }
Please help.

Replies are listed 'Best First'.
Re: bitwise comparison of files from two directories
by educated_foo (Vicar) on Feb 14, 2012 at 15:26 UTC
    Since you're apparently on Unix, see diff(1), particularly the "-r" and "-q" options.
      sorry, I'm newbee to PERL and unix. Can you please explain me, how to use diff? thanks