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

Greetings, I have noticed using the DirCompare.pm module that during a comparison of two directories, the comparison only searches for matching files "files with the same file name but different content" at the same "level" of the directory tree, I have noticed this same functionality with most comparison programs no matter what language they are written in, I understand the purpose behind only searching for matching files with matching names at the same level of the directory tree because files with matching names can exist in different folders but my question is how could one go about modifying DirCompare.pm to search all levels of the two directories being compared for matching files and unique files. Here is the code i am using along with DirCompare.pm Thanks for your time amd help.
use File::DirCompare; use File::Basename; $x='directory1'; $y='directory2'; File::DirCompare->compare("$x","$y", sub { my ($a, $b) = @_; if (! $b) { printf "Only in %s: %s\n", dirname($a), basename($a); } elsif (! $a) { printf "Only in %s: %s\n", dirname($b), basename($b); } else { print "Files $a and $b differ\n"; } });

Replies are listed 'Best First'.
Re: Modify DirCompare.pm
by dragonchild (Archbishop) on May 23, 2008 at 13:29 UTC
    1. Copy DirCompare.pm to a directory of your own.
    2. Modify DirCompare.pm to do what you want. Maybe inherit, maybe modify.
    3. Use your own copy, probably best to call it something else.
    It's open source for a reason.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      "1. copy DirCompare.pm to a directory of your own" I knew I forgot something, thanks
        If DirCompare doesn't do what you want, the code needs to be changed. Either you can do it or the author can do it. You doing it is quicker. If you don't like that, pay the author to put your requirements in. I've been paid to make changes in my modules on someone else's schedule, as have others.

        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?