help would be appreciated to help me understand what to pass to the "diff" or "traverse_sequences" to allow me to compare 4.1 and 4.0 and call them equal.
i have attempted to pass in both a named and an anonymous subroutine that attempts to access via symbolic reference the variables $a and $b of the scope calling "&$keyGen" in "_longestCommonSubsequence" which really calls my subroutine.
if i understand the camel book correctly, symbolic references do not work across packages. (just read that). hmphh!
in my sub i check if they are close; if so, take the avg and pump through sprintf. return either the original first parameter or the new avg.
then both calls to "&$keyGen" would be returning the same value.
much thanks, jim
sample code trying out my idea leaving in various attempts.
use warnings; use strict; use lib qw( /rshome/jaw2/lib/site_perl/5.8.0 ); use Algorithm::Diff qw( diff ); my @a = qw( 1.0 2.1 3.2 4.0 4.9 5.8 ); my @b = qw( 1.0 2.0 3.0 4.0 5.0 6.0 ); my @d = diff( \@a, \@b, sub { my( $o ) = @_; #my( $o, $aa, $bb ) = @_; #no strict 'refs'; my $d = abs( $a - $b ); #my $d = abs( $$aa - $$bb ); if( $d <= 0.1 ) { my $avg = sprintf "%14.6e", ( $a + $b ) / 2; #my $avg = sprintf "%14.6e", ( $$aa + $$bb ) / + 2; return $avg; } return $o; } ); #####'a', 'b' #my @d = diff( \@a, \@b, \&mykeygen, 'a', 'b' ); #my @d = diff( \@a, \@b, \&mykeygen, { 'a' => '$_[0]', 'b' => '$_[1]' +} ); #my @d = diff( \@a, \@b, \&mykeygen, '$_[0]', '$_[1]' ); print "d array:\n", join( "\n\t", @d ), "\n";
In reply to using Algorithm::Diff for floats by jim_neophyte
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |