Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Six way diff? (Solved. Low-tech rules!)

by BrowserUk (Patriarch)
on Apr 24, 2015 at 22:39 UTC ( [id://1124618]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

I have six chunks of 52 lines of very similar code that I need to isolate all the differences in.

I've been tackling it by eye, and have it mostly working, but there remains some small difference that I'm not seeing; and I'm going bug-eyed for looking.

Anyone any thoughts how to do a six-way diff?


Everything below is update.

I settled for a low tech solution that worked surprisingly well.

First, I put the six chunks of code into separate files. Then I wrote the following simple Perl script that loaded the lines of those files in to an AoAs: all the line 1s in to one array, all line 2s in to another; and so on; and then printed them to standard out:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @lines; for my $file ( qw[ x1.js x2.js y1.js y2.js z1.js z2.js ] ){ open FH, '<', $file or die $!; push @{ $lines[ $. ] }, $_ while <FH>; close FH; } for my $l ( @lines ) { next unless defined $l; print @$l; }

What I got after normalising the files and lines -- which was surprisingly quick by referencing the output -- was stuff that looked like this:

E:\Chart>diff6 | more gg = _GetGrid( this.Min.y / this.Parent.Zoom.y, this.Max.y / this.Pare +nt.Zoom.y, this.Scale.y ); gg = _GetGrid( this.Min.z / this.Parent.Zoom.z, this.Max.z / this.Pare +nt.Zoom.z, this.Scale.z ); gg = _GetGrid( this.Min.x / this.Parent.Zoom.x, this.Max.x / this.Pare +nt.Zoom.x, this.Scale.x ); gg = _GetGrid( this.Min.z / this.Parent.Zoom.z, this.Max.z / this.Pare +nt.Zoom.z, this.Scale.z ); gg = _GetGrid( this.Min.x / this.Parent.Zoom.x, this.Max.x / this.Pare +nt.Zoom.x, this.Scale.x ); gg = _GetGrid( this.Min.y / this.Parent.Zoom.y, this.Max.y / this.Pare +nt.Zoom.y, this.Scale.y ); if( this.GridDelta.y != 0 ) gg[1] = this.GridDelta.y; if( this.GridDelta.z != 0 ) gg[1] = this.GridDelta.z; if( this.GridDelta.x != 0 ) gg[1] = this.GridDelta.x; if( this.GridDelta.z != 0 ) gg[1] = this.GridDelta.z; if( this.GridDelta.x != 0 ) gg[1] = this.GridDelta.x; if( this.GridDelta.y != 0 ) gg[1] = this.GridDelta.y; var ii = 0; var ii = 0; var ii = 0; var ii = 0; var ii = 0; var ii = 0; for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { for( var jj = gg[2]; jj >= gg[0]; jj -= gg[1] ) { pp.y = jj * this.Parent.Zoom.y; pp.z = jj * this.Parent.Zoom.z; pp.x = jj * this.Parent.Zoom.x; pp.z = jj * this.Parent.Zoom.z; pp.x = jj * this.Parent.Zoom.x; pp.y = jj * this.Parent.Zoom.y; pp.z = this.Min.z; pp.y = this.Min.y; pp.z = this.Min.z; pp.x = this.Min.x; pp.y = this.Min.y; pp.x = this.Min.x; var vv = this.Parent.ScreenPos( pp ); var vv = this.Parent.ScreenPos( pp ); var vv = this.Parent.ScreenPos( pp ); var vv = this.Parent.ScreenPos( pp ); var vv = this.Parent.ScreenPos( pp ); var vv = this.Parent.ScreenPos( pp ); fromOV( this.Line[4][ii], vv.x, vv.y ); fromOV( this.Line[5][ii], vv.x, vv.y ); fromOV( this.Line[2][ii], vv.x, vv.y ); fromOV( this.Line[3][ii], vv.x, vv.y ); fromOV( this.Line[0][ii], vv.x, vv.y ); fromOV( this.Line[1][ii], vv.x, vv.y ); ...

I piped that into a file, wrapped it into a subroutine and eliminated the duplicates, then went through the sets of lines with differences and parameterised them one at a time. The result is:

Where first six lines are the call sites and the rest the fully parameterised function.

And the best bit: IT WORKS!

The names need work, but that's true for all the names in the library. And a job for tomorrow.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re: Six way diff?
by bitingduck (Chaplain) on Apr 24, 2015 at 22:53 UTC

    Print on transparencies and overlay them?

    But you'd have to find transparencies.

        I just banged out an AHK script that lets me hit Ctrl-Alt-# to set the current window to #0% opacity, and have it running in the background all the time.

        Stacking the windows with high transparency on the top is then easy.

        Hmm. Don't seem to have the source anywhere handy, but it is just a copy-paste of ten hardcoded hotkeys to winset opacity on the active window.

Re: Six way diff?
by tonto (Friar) on Apr 24, 2015 at 23:25 UTC
    Did you look at Diffuse ? (I don't know anything about it but I was finished with my work, so I Googled...)
      thats only 3 files, vimdiff does 4
        It says it can do an arbitrary number of files, it only shows an example of three.
Re: Six way diff? (gvim 4 way)
by Anonymous Monk on Apr 24, 2015 at 23:24 UTC
    Um :)   gVimPortable.exe  -d -g -R -y  one two three four five six?

    update: bah, cannot diff more than 4 buffers ... is 4 good?

    Do four then do four?

    Not sure if the above command does it or its some other vim setting, but all the buffers are split vertically :)

    not seen this http://vimcasts.org/episodes/comparing-buffers-with-vimdiff/

Re: Six way diff?
by Marshall (Canon) on Apr 25, 2015 at 01:06 UTC
    This sounds like a really, really tough problem from a very, very experienced Monk!

    I am not sure that I can help. Of course a data set as we all ask for, would be helpful.

    Right now, I am thinking of how to calculate essentially the "least common denominator" - what is the same between these versions. That is not an easy think to do and I'm not sure that such a thing would even be helpful.

    I am not sure of that a 6 way diff presentation would look like? I mean if even such a thing can be calculated by the computer, how would the human use it?.

    UPDATE: apparently my comments are completely unnecessary and a solution has been found.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1124618]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found