CC: | "Fischer, William M" <wfischer [...] lanl.gov> |
Subject: | "Documentation bug" for key-generation call in object interface |
Date: | Fri, 24 Aug 2012 17:03:07 +0000 |
To: | "bug-Algorithm-Diff [...] rt.cpan.org" <bug-Algorithm-Diff [...] rt.cpan.org> |
From: | "Fischer, William M" <wfischer [...] lanl.gov> |
Thanks for Algorithm::Diff! I had some difficulty figuring out how to call my own comparison subroutines using the oo interface, and would like to suggest the following patch to the documentation, which just adds the following lines to the pod:
------
For the OO interface, the key generation function should be passed as an anonymous hash with the hash-key 'keyGen':
sub ignore_letter_case { return uc(shift()); }
my $diff = Algorithm::Diff->new(\@list1,\@list2, { keyGen => \&ignore_letter_case } );
------
The 'obvious' syntax:
my $diff = Algorithm::Diff->new(\@list1,\@list2, \& my_comparison_sub ); # WRONG!
gave this error:
Not a HASH reference at /opt/local/lib/perl5/site_perl/5.12.3/Algorithm/Diff.pm line 589.
... and it took me a little while (and a peek into the source) to figure out what was wanted.
Thanks,
-- Will Fischer
Here's the patch (also attached as a file):
% LC_ALL=C TZ=UTC0 diff -Naur old/Diff.pm new/Diff.pm
--- old/Diff.pm 2006-07-31 05:55:36.000000000 +0000
+++ new/Diff.pm 2012-08-24 16:42:34.000000000 +0000
@@ -1662,6 +1662,13 @@
You may also pass additional parameters to the key generation function
if you wish.
+For the OO interface, the key generation function should be passed as
+an anonymous hash with the hash-key 'keyGen':
+
+sub ignore_letter_case { return uc(shift()); }
+
+my $diff = Algorithm::Diff->new(\@list1,\@list2, { keyGen => \&ignore_letter_case } );
+
=head1 ERROR CHECKING
If you pass these routines a non-reference and they expect a reference,
Show quoted text
______________________
Will Fischer, Ph.D.
net: wfischer@lanl.gov<mailto:wfischer@lanl.gov>
tel: 505-665-4149
fax: 505-665-3493
Group T-6, MS K710, Drop Point 03041003U
Los Alamos National Laboratory
Los Alamos, NM 87545
USA
Message body is not shown because sender requested not to inline it.