jim_neophyte has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using Algorithm::Diff for floats
by demerphq (Chancellor) on Jul 27, 2004 at 18:55 UTC | |
by jim_neophyte (Sexton) on Jul 27, 2004 at 19:42 UTC | |
|
Re: using Algorithm::Diff for floats
by BrowserUk (Patriarch) on Jul 27, 2004 at 20:45 UTC | |
by tye (Sage) on Jul 27, 2004 at 22:26 UTC | |
by BrowserUk (Patriarch) on Jul 27, 2004 at 22:47 UTC | |
by jim_neophyte (Sexton) on Jul 27, 2004 at 21:00 UTC | |
|
Re: using Algorithm::Diff for floats (Updated)
by BrowserUk (Patriarch) on Jul 27, 2004 at 22:13 UTC | |
by tye (Sage) on Jul 28, 2004 at 05:55 UTC | |
by BrowserUk (Patriarch) on Jul 28, 2004 at 06:11 UTC |