[Israel.pm] comparing files
Gabor Szabo
szabgab at gmail.com
Mon Jul 24 10:06:37 EEST 2006
On 7/23/06, Ephraim Dan <E.Dan at f5.com> wrote:
> > I would like to run diff on two files using a perl module.
> > Unfortunately Text::Diff cannot disregard white space differences.
>
> I think Text::Diff supports this using the KEYGEN argument, which is passed to Algorithm::Diff:
> http://search.cpan.org/~tyemq/Algorithm-Diff-1.1901/lib/Algorithm/Diff.pm#KEY_GENERATION_FUNCTIONS
>
> You would just pass it a coderef that returns a whitespace-stripped version of its argument, and it should just work...
>
> Totally untested example:
> my $diff = diff "file1.txt", "file2.txt", { KEYGEN => sub {
> my $s = shift; $s=~s/^\s*//; $s=~s/\s*$//; return $s; }
> };
Very nice, it indeed works.
thanks
Gabor
More information about the Perl
mailing list