-elsif($ok == 1 and $ok1 == 1)
- {
- @buffer = ();
- if($sort == 1)
- {
- @list3 = sort @list1;
- @list1=();
- @list1=@list3;
- @list3=();
-
- @list3 = sort @list2;
- @list2=();
- @list2=@list3;
- @list3=();
-
- $sort=0;
- }
- while(@list1 or @list2)
- {
- $line1 = shift (@list1);
- $line2 = shift (@list2);
- if($line2 and $line1)
- {
- if($line1 eq $line2){
- if($verbose == 1){print "$line1\n";}
- else{push @buffer, "$line1\n";}
-
- }
- else
- { if($verbose == 0){print @buffer};
- if($line2) {print "- $line2\n"};
- if($line1) {print "+ $line1\n"};
- die;
- }
- }
- else
- { if($verbose == 0){print @buffer};
- if($line2) {print "- $line2\n"};
- if($line1) {print "+ $line1\n"};
- die;
- }
- }
- $ok = 0;
- $ok1= 0;
- @list1=();
- @list2=();
- @buffer = ();
-}
\ No newline at end of file
+
+#my (@a,@b);
+#push @a,"bl1"; push @b,"bl1";
+#push @a,"bl2"; push @b,"bl2";
+#push @a,"bl3"; push @b,"bl3";
+#push @a,"bl4"; push @b,"bl4";
+#push @a,"bl5"; push @b,"bl5";
+#push @a,"bl6"; push @b,"bl6";
+#push @a,"bl7"; push @b,"bl7";
+##push @a,"Perl"; push @b,"ruby";
+#push @a,"END1"; push @b,"END1";
+#push @a,"END2"; push @b,"END2";
+#push @a,"END3"; push @b,"END3";
+#push @a,"END4"; push @b,"END4";
+#push @a,"END5"; push @b,"END5";
+#push @a,"END6"; push @b,"END6";
+#push @a,"END7"; push @b,"END7";
+#print "Identical:\n". build_diff(\@a,\@b);
+
+#@a = (); @b =();
+#push @a,"AZE"; push @b,"EZA";
+#print "Different:\n".build_diff(\@a,\@b);
+
+use Diff qw(diff); # postpone a bit to have time to change INC
+
+sub build_diff {
+ my $res;
+ my $diff = Diff->new(@_);
+
+ $diff->Base( 1 ); # Return line numbers, not indices
+ my $chunk_count = $diff->Next(-1); # Compute the amount of chuncks
+ return "" if ($chunk_count == 1 && $diff->Same());
+ $diff->Reset();
+ while( $diff->Next() ) {
+ my @same = $diff->Same();
+ if ($diff->Same() ) {
+ if ($diff->Next(0) > 1) { # not first chunk: print 2 first lines
+ $res .= ' '.$same[0]."\n" ;
+ $res .= ' '.$same[1]."\n" if (scalar @same>1);
+ }
+ $res .= "...\n" if (scalar @same>2);
+# $res .= $diff->Next(0)."/$chunk_count\n";
+ if ($diff->Next(0) < $chunk_count) { # not last chunk: print 2 last lines
+ $res .= ' '.$same[scalar @same -2]."\n" if (scalar @same>1);
+ $res .= ' '.$same[scalar @same -1]."\n";
+ }
+ }
+ next if $diff->Same();
+ map { $res .= "- $_\n" } $diff->Items(1);
+ map { $res .= "+ $_\n" } $diff->Items(2);
+ }
+ return $res;
+}
+
+