[Israel.pm] comparing files

Ephraim Dan E.Dan at F5.com
Sun Jul 23 16:51:36 EEST 2006


> 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; }
};




More information about the Perl mailing list