It only took years, but Algorithm::Diff finally has an OO interface which (IMO) transforms using the module from nearly an arcane art to quite simple programming (and more powerful).

Producing a standard 'diff' is so easy now that an example of one is in the synopsis for the module.

Comments welcome. I noticed a few missed word endings in the docs, so I'll put out an update after a bit.

- tye        

Replies are listed 'Best First'.
Re: OO Algorithm::Diff (finally) released
by rinceWind (Monsignor) on Sep 27, 2004 at 15:03 UTC
    Looks like I will be able to simplify my VCS::Lite in future releases. Well done!

    Any chance it could do diffs on things other than arrays? I've wondered if a version of diff could be passed two filehandles or two iterator callbacks.

    --
    I'm Not Just Another Perl Hacker

      Thanks!

      The nature of the algorithm requires that the data end up in arrays. So supporting iterators would just be bolted on to the front. So for the case of file handles, you might as well just use:

      my $diff = Algorithm::Diff->new( [<IN1>], [<IN2>] );

      as that will be as efficient as possible.

      For the case of other iterators, you might as well provide a general "iterate into a list" procedure that has nothing to do with Algorithm::Diff, for example:

      sub cvIterToList { my $cvIter = shift( @_ ); my @list; my $item; while( defined( $item= $cvIter->() ) ) { push @list, $item; } return \@list; }
      so:
      my $diff = Algorithm::Diff->new( cvIterToList($iter), [<IN>] );

      But I could certainly add such to A::Diff anyway. What other types of iterators should I support? Perhaps that is enough since other cases can be covered simply enough with something like:

      cvIterToList( sub { $obj->Next() } )

      - tye        

        The nature of the algorithm requires that the data end up in arrays. So supporting iterators would just be bolted on to the front.

        Do you really need to have entire list at once or does it operate on a window? Or does this change depending on the characterization of the differences?

        Maybe it might be worth a look whether Tie::File helps with files?

        Makeshifts last the longest.