Hi , My requirement is to compare two given directories.Inorder to achieve this i have used File::DirCompare perl module.And i have written the below program to get the output.
#!/usr/bin/perl # Simple diff -r --brief replacement use strict; use File::DirCompare; use File::Basename; use File::Find::Rule; my $dir1 = $ARGV[0]; my $dir2 = $ARGV[1]; File::DirCompare->compare($dir1, $dir2, sub { my ($a, $b) = @_; if (! $b) { if (-d $a) { # For unique directories, just report all the files printf "Only in %s: %s\n", dirname($_), basename($_) foreach File::Find::Rule->file()->in($a); } else { printf "Only in %s: %s\n", dirname($a), basename($a); } } elsif (! $a) { if (-d $b) { # For unique directories, just report all the files printf "Only in %s: %s\n", dirname($_), basename($_) foreach File::Find::Rule->file()->in($b); } else { printf "Only in %s: %s\n", dirname($b), basename($b); } } else { print "Files $a and $b differ\n"; } }); Let us Consider the below directory structure. Temp1 feb.c Temp10 Monday.c Jan.c Temp100 moon.c Similary another directory structure Temp2 feb.c Temp10 Tuesday.c Jan.c Temp200 sun.c Here i need to mention that the contents of the files feb.c in Temp1 and Temp2 are different.And Similarly the contents of the file Jan.c in Temp1/Temp10 and Temp2/Temp10 are different. SO now if i run the program i am getting the output as Files Temp1/Temp10/Jan.c and Temp2/Temp10/Jan.c differ Only in Temp1/Temp10/Temp100: moon.c Only in Temp2/Temp10/Temp200: sun.c Only in Temp2: Tuesday.c Files Temp1/feb.c and Temp2/feb.c differ Only in Temp1: monday.c But i need an organized output foramt like below. Files Temp1/Temp10/Jan.c and Temp2/Temp10/Jan.c differ Files Temp1/feb.c and Temp2/feb.c differ Only in Temp1/Temp10/Temp100:moon.c Only in Temp1: monday.c Only in Temp2/Temp10/Temp200: sun.c Only in Temp2: Tuesday.c SO first i want to print the files that differ in content.Next i want to print the files that are only in Temp1.At last i want to print the files that are only in Temp2. SO where do i need to change my code inorder to get my desired ouput.I am just a begineer in perl programming. I require ur help in this regard. Awiating ur reply, with regards, uday __________________________________________________________ Yahoo! India Answers: Share what you know. Learn something new http://in.answers.yahoo.com/