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

Before I dive into reinventing the wheel, does anyone know of an existing perl module which will help me:

1. Take a date range and a list of files which were created within that date range (inclusively).

2.Calculate and print the diffences between file 1 and file 2, file 1 and file 3, file 1 and file 4, etc. Basically, I'm looking for certain changes that took place withing a given time period.

The only thing close is Algorithm::Diff, but that doesn't seem to be relevant.

Replies are listed 'Best First'.
Re: Super Diff?
by Anonymous Monk on Feb 12, 2001 at 22:18 UTC
    Algorithm::Diff is pretty good for producing diff like output for two variables in Perl, but I would definitly just use: `/usr/bin/diff $file[1] $file[2]` to get the diff of files, its simpler. Also I'd suggest File::Find with a wanted funciton that checks the date range in order to pick your files

    Algorithm::Diff useage for difflike output looks something like:

    sub diffy { my $output; my @one = split(/\n/, $_[0]); my @two = split(/\n/, $_[1]); my $equ = $_[2] || "=="; my $sub = $_[3] || "--"; my $add = $_[4] || "++"; my $eqX = $_[5] || ""; my $suX = $_[6] || ""; my $adX = $_[7] || ""; use Algorithm::Diff qw(traverse_sequences); traverse_sequences(\@one, \@two, { MATCH => sub { $output .= "$equ$one[shift]$eqX\n"}, DISCARD_A => sub { $output .= "$sub$one[shift]$suX\n"}, DISCARD_B => sub { $output .= "$add$two[shift,shift]$adX\n"}, }); return $output; }
    Which is sorta odd looking, but now that you have that code, you don't really have to think about it. Here you can pass in $one and $two as variables holding multi-line input, and optionally pass in start tags for matching lines, deleted lines, and added lines, as well as the end tags for the same.

    -Daniel

    Edit: 2001-03-03 by neshura

      whops; I'm not anonymous
Re: Super Diff?
by knight (Friar) on Feb 12, 2001 at 21:50 UTC
    Why doesn't Algorithm::Diff seem relevant? It sounds like what you're looking for is a wrapper that selects the specific files based on the supplied date range (easy enough), and then loops through the file list applying Algorithm::Diff to do the heavy lifting and print the differences.
Re: Super Diff?
by extremely (Priest) on Feb 12, 2001 at 21:58 UTC
    I suspect that you are going to be inventing at least a few spokes on that wheel. Step one is quite doable with File::Find which should be already installed with Perl. Step 2 is all you. You should decide how to parse the files and compare them. Do you really need a full file diff? If so you may just consider jobbing it out to the unix diff. If you are just looking for one or two specific things I'd recommend parsing it a little more manually than diff.

    Sorry I can't help more than that but it is a weird thing by the description.

    --
    $you = new YOU;
    honk() if $you->love(perl)

      It is weird. The frustrating part is that the reason I can't do:
      foreach my $file(@list_of_files_to_compare_to_start_date_file){ if ($file_a != $file) { print "$file\n"; } }
      is that I need to build in logic for brain-dead people that are responsible for certain naming-conventions contained in these files. Because of this, the above could incorrectly report a not-equalling b, based upon my definition of "equals"